rkerror

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: Apache-2.0 Imports: 3 Imported by: 12

Documentation

Overview

Package rkerror defines RK style API errors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    int           `json:"code" yaml:"code"`       // Code represent codes in response
	Status  string        `json:"status" yaml:"status"`   // Status represent string value of code
	Message string        `json:"message" yaml:"message"` // Message represent detail message
	Details []interface{} `json:"details" yaml:"details"` // Details is a list of details in any types in string
}

Error defines standard error types of rk style

func (*Error) Error

func (err *Error) Error() string

Error returns string of error

type ErrorResp

type ErrorResp struct {
	Err *Error `json:"error" yaml:"error"` // Err is RK style error type
}

ErrorResp is standard rk style error

func FromError

func FromError(err error) *ErrorResp

FromError converts error to ErrorResp

func New

func New(opts ...Option) *ErrorResp

New a error response with options

type Option

type Option func(*ErrorResp)

Option is ErrorResp option

func WithDetails

func WithDetails(details ...interface{}) Option

WithDetails provides any type of error details into error response

func WithHttpCode

func WithHttpCode(code int) Option

WithHttpCode provides response code

func WithMessage

func WithMessage(message string) Option

WithMessage provides messages along with response

Jump to

Keyboard shortcuts

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