Skip to content

openshift-online/weberr

Repository files navigation

weberr logo

weberr

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 Report Card Build Status GoDoc License

go get github.com/zgalor/weberr

Read the package documentation for more information.

Quick Start

make build       # Build the package
make test        # Run all tests

Divergences from pkg/errors

  • We chose weberr.Wrapf(nil, ...) and similar wrapping functions should return a new error, whereas errors.Wrapf(nil, ...) historically returns nil.

License

BSD-2-Clause

Logo

[ awesome logo image by gophers... ]

Installation

go get github.com/openshift-online/weberr

Or in more recent Go versions:

go get github.com/openshift-online/weberr@latest

Usage

import "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 500

Development

go test ./...         # Run all tests
go vet ./...          # Run static analysis

Contributing

  1. Fork this repository
  2. Create a feature branch from master
  3. Make your changes with tests
  4. Submit a pull request

About

A golang error package for web services

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors