package module
Version: v0.1.0 Latest Latest

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

Go to latest
Published: May 6, 2021 License: MIT Imports: 4 Imported by: 0



httperr is a simple interface for easily implementing errors in http responses.

It's as simple as calling JSON on a basic error.

                Message:    "There was an error retrieving the items",
                ErrorCode:  "GI0001",
                StatusCode: 500,

The default DefaultError changes the status code of the response on Render, then is marshalled.

This was inspired by render, but simplified and modified to fit the usual simple error handling



Package httperr implements simple http errors



This section is empty.


This section is empty.


func JSON

func JSON(w http.ResponseWriter, r *http.Request, ren Renderer)

JSON encodes the payload as JSON and sends it back. It calls the Render function of the renderer, so that you can set-up Anything you want to inside it, such as logging the error locally or such


type DefaultError

type DefaultError struct {
	Message    string `json:"message"`
	ErrorCode  string `json:"code"`
	StatusCode int    `json:"-"`

DefaultError defines a simple DefaultError.

func (*DefaultError) Error

func (e *DefaultError) Error() string

func (*DefaultError) Render

func (e *DefaultError) Render(w http.ResponseWriter, r *http.Request) error

Render implements Renderer for DefaultError

type Renderer

type Renderer interface {
	Render(http.ResponseWriter, *http.Request) error

Renderer implements the Render function. Its goal is to prepare the JSON rendering

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL