Package weberr based on https://github.com/pkg/errors with a few additions:
- Set an error type that corresponds to HTTP status returned by this error
- Set a user friendly error message (in addition to the error message that will be logged)
- Add arbitrary details to the error
go get github.com/zgalor/weberr
Read the package documentation for more information.
make build # Build the package
make test # Run all tests- We chose
weberr.Wrapf(nil, ...)and similar wrapping functions should return a new error, whereaserrors.Wrapf(nil, ...)historically returns nil.
BSD-2-Clause
[ awesome logo image by gophers... ]
go get github.com/openshift-online/weberrOr in more recent Go versions:
go get github.com/openshift-online/weberr@latestimport "github.com/openshift-online/weberr"
// Create a typed error with an HTTP status
err := weberr.New(http.StatusNotFound, "resource not found")
// Wrap an existing error with HTTP context
err = weberr.Wrap(err, http.StatusInternalServerError, "failed to process request")
// Set a user-friendly message
err = weberr.WithUserMessage(err, "Something went wrong, please try again")
// Retrieve the HTTP status code
code := weberr.HTTPStatusCode(err) // returns 500go test ./... # Run all tests
go vet ./... # Run static analysis- Fork this repository
- Create a feature branch from
master - Make your changes with tests
- Submit a pull request
