Documentation ¶
Overview ¶
nolint:ireturn
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyResponse = errors.New("empty provider response")
var ErrUnknownResponseFormat = errors.New("unknown response format")
Functions ¶
Types ¶
type DirectFaultyResponder ¶
DirectFaultyResponder is an implementation of FaultyResponseHandler. It is a simple wrapper that allows you to directly provide an implementation of handler callback. First consider FaultyResponder that reduces the boilerplate.
func (DirectFaultyResponder) HandleErrorResponse ¶
func (r DirectFaultyResponder) HandleErrorResponse(res *http.Response, body []byte) error
type ErrorDescriptor ¶
ErrorDescriptor enhances base error with extra message. Every implementor decides how server response will be converted, and how important message will be formated into helpful error.
type ErrorHandler ¶
type ErrorHandler struct { JSON FaultyResponseHandler XML FaultyResponseHandler HTML FaultyResponseHandler Custom map[Mime]FaultyResponseHandler }
ErrorHandler invokes a function that matches response media type with parse error, ex: JSON<->JsonParserMethod otherwise defaults to general opaque error interpretation.
type FaultyResponder ¶
type FaultyResponder struct {
// contains filtered or unexported fields
}
FaultyResponder is an implementation of FaultyResponseHandler. It uses common techniques to handle error response returned by provider.
func NewFaultyResponder ¶
func NewFaultyResponder(errorSwitch *FormatSwitch, statusCodeMap map[int]error) *FaultyResponder
NewFaultyResponder creates error responder that will be used when provider responds with erroneous payload.
- FormatSwitch will be used to select the best matching error format. It can be null if you don't want pretty parsing and formating.
- StatusCodeMap will be used to enhance error message. This is an optional map that will precede any default status to error mapping.
func (FaultyResponder) HandleErrorResponse ¶
func (r FaultyResponder) HandleErrorResponse(res *http.Response, body []byte) error
type FaultyResponseHandler ¶
FaultyResponseHandler used to parse erroneous response.
type FormatSwitch ¶
type FormatSwitch struct {
// contains filtered or unexported fields
}
FormatSwitch allows to select the most appropriate format. Switch will traverse every template stopping at the closest match, which best describes server response. Then ErrorDescriptor will convert itself into a composite go error.
func NewFormatSwitch ¶
func NewFormatSwitch(templates ...FormatTemplate) *FormatSwitch
func (FormatSwitch) ParseJSON ¶
func (s FormatSwitch) ParseJSON(data []byte) ErrorDescriptor
ParseJSON selects a template, populates it, and returns the result. If the error response is concise and clear, it’s used directly; otherwise, the entire response is used to build an error. This strategy ensures complete visibility into the provider’s response.
The JSON data may either contain a single object, interpreted as an ErrorDescriptor, or an array of objects, with each mapped to matching ErrorDescriptor.
type FormatTemplate ¶
type FormatTemplate struct { // MustKeys is a list of important keys that if all present will signify the match for Template. MustKeys []string // Template is a factory that returns a struct, which will be used to flush the data into. Template func() ErrorDescriptor }
FormatTemplate holds concrete struct that represent erroneous server response. It is used by FormatSwitch.