serviceerror

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2019 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorCodeSourceDecorator

type ErrorCodeSourceDecorator struct {
	ErrorSource *grncerror.ServiceErrorManager
}

func (*ErrorCodeSourceDecorator) DecorateComponent

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

func (*ErrorCodeSourceDecorator) OfInterest

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

type ServiceErrorConsumerDecorator

type ServiceErrorConsumerDecorator struct {
	ErrorSource *grncerror.ServiceErrorManager
}

func (*ServiceErrorConsumerDecorator) DecorateComponent

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

func (*ServiceErrorConsumerDecorator) OfInterest

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

type ServiceErrorManagerFacilityBuilder

type ServiceErrorManagerFacilityBuilder struct {
}

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

func (*ServiceErrorManagerFacilityBuilder) BuildAndRegister

See FacilityBuilder.BuildAndRegister

func (*ServiceErrorManagerFacilityBuilder) DependsOnFacilities

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

See FacilityBuilder.DependsOnFacilities

func (*ServiceErrorManagerFacilityBuilder) FacilityName

func (fb *ServiceErrorManagerFacilityBuilder) FacilityName() string

See FacilityBuilder.FacilityName

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL