Documentation
¶
Index ¶
Examples ¶
Constants ¶
const ( // CodeBadRequestError indicates that the request is not properly formatted. CodeBadRequestError = 400 // CodeForbiddenError means that the current user does not have the required permissions to access the requested resource. CodeForbiddenError = 403 // CodeNotFoundError represents a request for a resource that does not exist, such as a database query that returns "not found" CodeNotFoundError = 404 // CodeInternalError represents a generic error message, given when an unexpected condition was encountered and no more specific message is suitable. CodeInternalError = 500 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsolePlugin ¶ added in v0.9.0
type ConsolePlugin struct{}
ConsolePlugin prints errors to the system console.
func (ConsolePlugin) Report ¶ added in v0.9.0
func (consolePlugin ConsolePlugin) Report(err *Error)
Report implements the `Plugin` interface, which allows the ConsolePlugin to be called by the Error.Report() method.
type Error ¶
type Error struct {
Code int `json:"code"` // Numeric error code (such as an HTTP status code) to report to the client.
Location string `json:"location"` // Function name (or other location description) of where the error occurred
Message string `json:"message"` // Primary (top-level) error message for this error
TimeStamp time.Time `json:"timestamp"` // Unix Epoch timestamp of the date/time when this error was created
Details []interface{} `json:"details"` // Additional information related to this error message, such as parameters to the function that caused the error.
InnerError *Error `json:"innerError"` // An underlying error object used to identify the root cause of this error.
}
Error represents a runtime error. It includes
func New ¶
New returns a new Error object
Example ¶
// Mock an error
thisBreaks := func() error {
return errors.New("Something failed")
}
// Try something that fails
if err := thisBreaks(); err != nil {
// Populate a derp.Error with everything you know about the error
result := New(CodeInternalError, "Example", "Something broke in `thisBreaks`", err.Error())
// Call .Report() to send an error to Ops. This is a system-wide
// configuration that's set up during initialization.
result.Report()
}
func (*Error) Error ¶
Error implements the Error interface, which allows derp.Error objects to be used anywhere a standard error is used.
func (*Error) ErrorCode ¶ added in v0.9.4
ErrorCode returns the error Code embedded in this Error. This is useful for matching interfaces in other package.
func (*Error) NotFound ¶ added in v0.9.0
NotFound returns TRUE if the error `Code` is a 404 / Not Found error.
func (*Error) Report ¶ added in v0.9.0
Report sends this error to all configured plugins, to be reported via their various error reporting channels.
type Plugin ¶
type Plugin interface {
Report(*Error)
}
Plugin wraps the "Report" method, which reports a derp error to an external source. Reporters are responsible for handling and swallowing any errors they generate.
type PluginList ¶
type PluginList []Plugin
PluginList represents an array of plugins, which will be called in succession whenever the Error.Report() function is called.
var Plugins PluginList
Plugins is the array of objects that are able to report a derp when err.Report() is called.
func (PluginList) Add ¶
func (list PluginList) Add(plugin Plugin) PluginList
Add registers a new plugin to the system-wide configuration. This lets the developer configure and append additional plugins during initialization. It should be called during system startup only.
func (PluginList) Clear ¶
func (list PluginList) Clear() PluginList
Clear removes all plugins from the system-wide configuration. It is useful for removing the library default Console() from the list of plugins, in the event that you don't want to report errors to the console.