httputil

package
v12.1.9-0...-e9b74bf Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InternalServerError

func InternalServerError(ctx iris.Context, err error, format string, args ...interface{})

InternalServerError logs to the server's terminal and dispatches to the client the 500 Internal Server Error. Internal Server errors are critical, so we log them to the `os.Stderr`.

func InternalServerErrorJSON

func InternalServerErrorJSON(ctx iris.Context, err error, format string, args ...interface{})

InternalServerErrorJSON acts exactly like `InternalServerError` but instead it sends the data as JSON. Useful for APIs.

func LogFailure

func LogFailure(logger io.Writer, ctx iris.Context, err HTTPError)

LogFailure will print out the failure to the "logger".

func RuntimeCallerStack

func RuntimeCallerStack() (s string)

RuntimeCallerStack returns the app's `file:line` stacktrace to give more information about an error cause.

Types

type HTTPError

type HTTPError struct {
	Stack       string    `json:"-"` // the whole stacktrace.
	CallerStack string    `json:"-"` // the caller, file:lineNumber
	When        time.Time `json:"-"` // the time that the error occurred.
	// ErrorCode int: maybe a collection of known error codes.
	StatusCode int `json:"statusCode"`
	// could be named as "reason" as well
	//  it's the message of the error.
	Description string `json:"description"`
	// contains filtered or unexported fields
}

HTTPError describes an HTTP error.

func Fail

func Fail(ctx iris.Context, statusCode int, err error, format string, args ...interface{}) HTTPError

Fail will send the status code, write the error's reason and return the HTTPError for further use, i.e logging, see `InternalServerError`.

func FailJSON

func FailJSON(ctx iris.Context, statusCode int, err error, format string, args ...interface{}) HTTPError

FailJSON will send to the client the error data as JSON. Useful for APIs.

func UnauthorizedJSON

func UnauthorizedJSON(ctx iris.Context, err error, format string, args ...interface{}) HTTPError

UnauthorizedJSON sends JSON format of StatusUnauthorized(401) HTTPError value.

Jump to

Keyboard shortcuts

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