errs

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: MIT Imports: 5 Imported by: 0

README

errs

This package provides simple error wrappers to add additional details to the errors and handle them in graphql.

Frontend Error

A frontend error can be created like this:

err := someFunction()
if err != nil {
    err = errs.NewFrontendError("Whoops", "error_whoops", err)
    return err
}

It may wrap an existing error and contains details and an error code. The presenter will log all of those information but will only pass the details and the error code to the frontend.

Detailed Error

A detailed error can be created like this:

err := someFunction()
if err != nil {
    err = errs.NewDetailedError("Whoops", err)
    return err
}

It is used to add additional information to an error to make debugging easier. The presenter will log all of those information but won't pass anything to the frontend.

Presenter

The presenter is build to be used with gqlgen. It logs all errors but manages what information should be sent to the frontend.

1. Errors which has a Location are GraphQL document based errors and will be passed
2. Details from frontend errors will be extracted and sent to the frontend
3. Else a generic "a server error occured" error will be sent to the frontend

The thought of this is to have more control of what information will be sent to the frontend to prevent eventual unwanted data leaks.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorPresenter

func ErrorPresenter(ctx context.Context, err error) *gqlerror.Error

func NewDetailedError

func NewDetailedError(details string, err error) error

func NewFrontendError

func NewFrontendError(details string, errorCode string, err error) error

Types

type DetailedError

type DetailedError struct {
	Details string
	Err     error
}

DetailedError contains additional information to write in the server logs for debugging purpose

func (DetailedError) Error

func (d DetailedError) Error() string

func (DetailedError) Unwrap

func (d DetailedError) Unwrap() error

type FrontendError

type FrontendError struct {
	Details   string
	ErrorCode string
	Err       error
}

FrontendError contains detail information to be sent to the frontend

func (FrontendError) Error

func (d FrontendError) Error() string

func (FrontendError) Unwrap

func (d FrontendError) Unwrap() error

Jump to

Keyboard shortcuts

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