Skip to content

estellarxtech/go-httpe

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-httpe - HTTP Error Package (echo)

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.

Installation

go get github.com/yourusername/httpe

Usage

Creating a New HTTP Error

err := httpe.NewHTTPError(404, "Not Found")

Setting an Internal Error

internalErr := errors.New("Some internal error")
httpErr := err.SetInternal(internalErr)

Unwrapping an Error

unwrappedErr := err.Unwrap()

Getting the HTTP Status Code

code := err.Code()

Parsing Error Messages

e := httpe.NewHTTPError(400, "field1: message1; field2: message2")
e.ParseMessageToErrors()

Returning HTTP Error Response

resp := httpe.NewHTTPError(400, "field1: message1; field2: message2").Return()

Adding Internal Error to HTTP Error Response

internalError := errors.New("internal error")
resp := e.WithInternal(internalError)

Testing

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.


Versioning and license

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

About

Package handler Error in Echo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%