errors

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package errors defines some well defined errors, like incomplete/wrong request data or object not found(404), for the purpose of internationalization.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAuthorized = errors.New("rooms/web: not authorized")

	ErrDenied = errors.New("rooms: this key has been banned")
)

Functions

This section is empty.

Types

type DatabaseError

type DatabaseError struct{ Reason error }

func (DatabaseError) Error

func (e DatabaseError) Error() string

type ErrBadRequest

type ErrBadRequest struct {
	Where   string
	Details error
}

func (ErrBadRequest) Error

func (br ErrBadRequest) Error() string

func (ErrBadRequest) Unwrap

func (err ErrBadRequest) Unwrap() error

type ErrForbidden

type ErrForbidden struct{ Details error }

func (ErrForbidden) Error

func (f ErrForbidden) Error() string

type ErrGenericLocalized

type ErrGenericLocalized struct{ Label string }

ErrGenericLocalized is used for one-off errors that primarily are presented for the user. The contained label is passed to the i18n engine for translation.

func (ErrGenericLocalized) Error

func (err ErrGenericLocalized) Error() string

type ErrNotFound

type ErrNotFound struct{ What string }

func (ErrNotFound) Error

func (nf ErrNotFound) Error() string

type ErrRedirect

type ErrRedirect struct {
	Path string

	// reason will be added as a flash error
	Reason error
}

ErrRedirect is used when the controller decides to not render a page

func (ErrRedirect) Error

func (err ErrRedirect) Error() string

func (ErrRedirect) Unwrap

func (err ErrRedirect) Unwrap() error

type ErrorHandler

type ErrorHandler struct {
	// contains filtered or unexported fields
}

func NewErrorHandler

func NewErrorHandler(locHelper *i18n.Helper, flashes *FlashHelper) *ErrorHandler

func (*ErrorHandler) Handle

func (eh *ErrorHandler) Handle(rw http.ResponseWriter, req *http.Request, code int, err error)

func (*ErrorHandler) SetRenderer

func (eh *ErrorHandler) SetRenderer(r *render.Renderer)

SetRenderer needs to update the rendere later since we need to pass ErrorHandler into render.New (ie. befor we get the pointer for r)

type FlashHelper

type FlashHelper struct {
	// contains filtered or unexported fields
}

func NewFlashHelper

func NewFlashHelper(s sessions.Store, loc *i18n.Helper) *FlashHelper

func (FlashHelper) AddError

func (fh FlashHelper) AddError(rw http.ResponseWriter, req *http.Request, err error)

AddError adds a FlashError and translates the passed err using localizeError()

func (FlashHelper) AddMessage

func (fh FlashHelper) AddMessage(rw http.ResponseWriter, req *http.Request, label string)

AddMessage expects a i18n label, translates it and adds it as a FlashNotification

func (FlashHelper) GetAll

func (fh FlashHelper) GetAll(rw http.ResponseWriter, req *http.Request) ([]FlashMessage, error)

GetAll returns all the FlashMessages, emptys and updates the store

type FlashKind

type FlashKind uint
const (

	// FlashError signals that a problem occured
	FlashError FlashKind
	// FlashNotification represents a normal message (like "xyz added/updated successfull")
	FlashNotification
)

type FlashMessage

type FlashMessage struct {
	Kind    FlashKind
	Message template.HTML
}

type PageNotFound

type PageNotFound struct{ Path string }

func (PageNotFound) Error

func (e PageNotFound) Error() string

Jump to

Keyboard shortcuts

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