Skip to content

๐Ÿ—‘ apperr provides a unified framework- and network-agnostic error generation interface. Errors can be localized and converted to GRPC, Twirp, HTTP, etc. equivalents

License

Notifications You must be signed in to change notification settings

harwoeck/apperr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

29 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ—‘ apperr

apperr provides a unified application error generation interface. Errors can be localized and converted to GRPC, Twirp, HTTP, etc. equivalents

Go Reference

Installation

To install apperr, simly run:

$ go get github.com/harwoeck/apperr

Usage

Create

To create errors use one of the provided functions from apperr, like apperr.Unauthenticated(msg)

err := apperr.Unauthenticated("provided password is invalid",
    apperr.Localize("INVALID_PASSWORD"))

apperr can provide localized error messages to users, when a LocalizationProvider is available. In order to add a translation message id to your *AppError you can use one of the provided Option (in the example Localize(messageID) is used)

Render

In order to render an *AppError into a *RenderedError use the static function Render:

rendered, _ := apperr.Render(err, apperr.RenderLocalized(adapter, "en-US"))

Convert

Use the Convert function from your installed converter to translate the *RenderedError from last step to your frameworks native error type:

  • GRPC
    • Install converter go get github.com/harwoeck/apperr/x/grpcerr
    • grpcStatus, err := grpcerr.Convert(*finalized.Error)
  • HTTP
    • Install converter go get github.com/harwoeck/apperr/x/httperr
    • httpStatus, httpBody, err := httperr.Convert(*finalized.Error)
  • Twirp
    • Install converter go get github.com/harwoeck/apperr/x/twirperr
    • twirpError := twirperr.Convert(*finalized.Error)
  • Terminal or Console
    • Install converter go get github.com/harwoeck/apperr/x/terminalerr
    • output := terminalerr.Convert(*finalized.Error)
      fmt.Println(output)

About

๐Ÿ—‘ apperr provides a unified framework- and network-agnostic error generation interface. Errors can be localized and converted to GRPC, Twirp, HTTP, etc. equivalents

Topics

Resources

License

Stars

Watchers

Forks

Languages