json_errors

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

README

json_errors provides a simple error handling for your REST applications. PkgGoDev Go Report Card

Features:

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

Installation:

go get github.com/pchchv/json_errors

Usage:

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())
	}
}
go run main.go
Output:
{"message":"Message about error","details":{"message":"nope"}}
See examples for more.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(message string) error

New returns a new `jerr.BaseError` with given values.

func Wrap

func Wrap(err error, message string) error

Wrap adds `err` to the `details` field of the new `jerr.BaseError`.

Types

type BaseError

type BaseError interface {
	Error() string
}

BaseError interface reveals additional information about the error. Implements a built-in error interface.

Directories

Path Synopsis
examples
http command
simple command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL