granitic: github.com/graniticio/granitic/facility/serviceerror Index | Files

package serviceerror

import "github.com/graniticio/granitic/facility/serviceerror"

Package serviceerror provides the ServiceErrorManager facility which provides error message management.

This facility is documented in detail at http://granitic.io/1.0/ref/service-errors

Error definitions

The purpose of the ServiceErrorManager is to allow error messages to be defined in a single place rather than be embedded in code. When application code needs to raise or work with an error, a short code is used to refer to the error and is used to lookup its related message.

Error definitions are stored in your application's configuration files and will look something like:

{
  "serviceErrors": [
	["C", "CREATE_RECORD", "Cannot create a record with the information provided."],
	["C", "RECORD_NAME", "Record names must be 1-128 characters long."],
	["C", "ARTIST_NAME", "Artist names must be 1-64 characters long."]
  ]
}

This example defines three errors with three parts that correspond to the fields in a ws.CategorisedError. The first element of each definition is the short-hand form of the error category (see ws.ServiceErrorCategory), the second is a unique code for the error and the third is a (normally human readable) error message.

Changing config location

By default, the ServiceErrorManager expects definitions to be available at the config path

serviceErrors

as in the example above. This can be overridden by modifying the ServiceErrorManager facility configuration like:

{
  "ServiceErrorManager":{
    "ErrorDefinitions": "my.errors.path"
  }
}

Panic on missing

If your application code uses an error code that has no corresponding definition, you can choose how the ServiceErrorManager will react. By default, the ServiceErrorManager will panic - this should be a development/test phase failure. If for some reason your application might reach production with error codes with missing definitions, you can set:

{
  "ServiceErrorManager":{
    "PanicOnMissing": false
  }
}

In this case, ServiceErrorManager will return nil when asked for the definition of an unknown code.

Index

Package Files

builder.go serviceerror.go

type ErrorCodeSourceDecorator Uses

type ErrorCodeSourceDecorator struct {
    ErrorSource *grncerror.ServiceErrorManager
}

func (*ErrorCodeSourceDecorator) DecorateComponent Uses

func (ecs *ErrorCodeSourceDecorator) DecorateComponent(component *ioc.Component, container *ioc.ComponentContainer)

func (*ErrorCodeSourceDecorator) OfInterest Uses

func (ecs *ErrorCodeSourceDecorator) OfInterest(component *ioc.Component) bool

type ServiceErrorConsumerDecorator Uses

type ServiceErrorConsumerDecorator struct {
    ErrorSource *grncerror.ServiceErrorManager
}

func (*ServiceErrorConsumerDecorator) DecorateComponent Uses

func (secd *ServiceErrorConsumerDecorator) DecorateComponent(component *ioc.Component, container *ioc.ComponentContainer)

func (*ServiceErrorConsumerDecorator) OfInterest Uses

func (secd *ServiceErrorConsumerDecorator) OfInterest(component *ioc.Component) bool

type ServiceErrorManagerFacilityBuilder Uses

type ServiceErrorManagerFacilityBuilder struct {
}

Constructs an instance of ServiceErrorManager and registers it as a component.

func (*ServiceErrorManagerFacilityBuilder) BuildAndRegister Uses

func (fb *ServiceErrorManagerFacilityBuilder) BuildAndRegister(lm *logging.ComponentLoggerManager, ca *config.ConfigAccessor, cn *ioc.ComponentContainer) error

See FacilityBuilder.BuildAndRegister

func (*ServiceErrorManagerFacilityBuilder) DependsOnFacilities Uses

func (fb *ServiceErrorManagerFacilityBuilder) DependsOnFacilities() []string

See FacilityBuilder.DependsOnFacilities

func (*ServiceErrorManagerFacilityBuilder) FacilityName Uses

func (fb *ServiceErrorManagerFacilityBuilder) FacilityName() string

See FacilityBuilder.FacilityName

Package serviceerror imports 8 packages (graph) and is imported by 1 packages. Updated 2016-10-26. Refresh now. Tools for package owners.