The httpe
package in Go provides utilities for handling HTTP errors in a structured way. It allows creation of HTTP error objects with a specific status code and message, including optional internal error details. The package also supports parsing error messages into structured formats.
go get github.com/yourusername/httpe
err := httpe.NewHTTPError(404, "Not Found")
internalErr := errors.New("Some internal error")
httpErr := err.SetInternal(internalErr)
unwrappedErr := err.Unwrap()
code := err.Code()
e := httpe.NewHTTPError(400, "field1: message1; field2: message2")
e.ParseMessageToErrors()
resp := httpe.NewHTTPError(400, "field1: message1; field2: message2").Return()
internalError := errors.New("internal error")
resp := e.WithInternal(internalError)
The package includes a comprehensive suite of tests to ensure functionality:
func TestNewHTTPError(t *testing.T) {
// ...
}
func TestSetInternal(t *testing.T) {
// ...
}
// ... additional test functions ...
Refer to the test suite for more detailed examples of how to use the httpe
package.
Our version numbers follow the semantic versioning specification. You can see the available versions by checking the tags on this repository. For more details about our license model, please take a look at the LICENSE file.
2024, thiagozs