JSON Errors for Go

PkgGoDev Go (build) Go Report Card CodeQL

jerr provides a simple error handling for your rest applications.

Features

  • Compatible with built-in error interface
  • Error wrapping
  • JSON escaping

Requirements

Getting Started

go get github.com/erdaltsksn/jerr
touch main.go

main.go:

package main

import (
    "fmt"

    "github.com/erdaltsksn/jerr"
)

func main() {
    err := someFunc()
    if err != nil {
        wrapped := jerr.Wrap(err, "Message about error")
        fmt.Println(wrapped.Error())
    }
}

func someFunc() error {
    return jerr.New("nope")
}
go run main.go

Output:

{"message":"Message about error","details":{"message":"nope"}}

Installation

go get github.com/erdaltsksn/jerr

Updating / Upgrading

go get -u github.com/erdaltsksn/jerr

Usage

// Simple error.
errSimple := jerr.New("Error Message")

// An error that wraps another error.
err := SomeFunc()
if err != nil {
    fmt.Print(jerr.Wrap(err, "Message about error"))
}

Check out examples directory for more.

Contributing

If you want to contribute to this project and make it better, your help is very welcome. See CONTRIBUTING for more information.

Security Policy

If you discover a security vulnerability within this project, please follow our Security Policy Guide.

Code of Conduct

This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.

Disclaimer

In no event shall we be liable to you or any third parties for any special, punitive, incidental, indirect or consequential damages of any kind, or any damages whatsoever, including, without limitation, those resulting from loss of use, data or profits, and on any theory of liability, arising out of or in connection with the use of this software.

Jerr

JSON errors for Go Rest APIs.

Jerr Info

⭐ Stars 13
🔗 Homepage github.com
🔗 Source Code github.com
🕒 Last Update 7 months ago
🕒 Created 2 years ago
🐞 Open Issues 0
➗ Star-Issue Ratio Infinity
😎 Author erdaltsksn