https://github.com/pchchv/json_errors
JSON errors for Go Rest APIs
https://github.com/pchchv/json_errors
api error error-handling error-messages errors go go-library go-module go-package golang golang-library golang-module golang-package json json-error rest rest-api rest-errors
Last synced: 5 months ago
JSON representation
JSON errors for Go Rest APIs
- Host: GitHub
- URL: https://github.com/pchchv/json_errors
- Owner: pchchv
- License: apache-2.0
- Created: 2023-05-31T07:26:05.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-07T07:55:52.000Z (almost 3 years ago)
- Last Synced: 2025-10-12T13:07:00.630Z (5 months ago)
- Topics: api, error, error-handling, error-messages, errors, go, go-library, go-module, go-package, golang, golang-library, golang-module, golang-package, json, json-error, rest, rest-api, rest-errors
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `json_errors` provides a simple error handling for your REST applications. [](https://pkg.go.dev/github.com/pchchv/json_errors) [](https://goreportcard.com/report/github.com/pchchv/json_errors)
## Features:
* Compatible with built-in `error` interface
* Error wrapping
* JSON escaping
#
## Installation:
```bash
go get github.com/pchchv/json_errors
```
#
## Usage:
```go
package main
import (
"fmt"
"github.com/pchchv/json_errors"
)
func someFunc() error {
return json_errors.New("nope")
}
func main() {
if err := someFunc(); err != nil {
wrapped := json_errors.Wrap(err, "Message about error")
fmt.Println(wrapped.Error())
}
}
```
```bash
go run main.go
```
### Output:
```json
{"message":"Message about error","details":{"message":"nope"}}
```
### See [examples](examples) for more.
#