Documentation ¶
Index ¶
- Constants
- func WriteResponse(ctx context.Context, err error, w http.ResponseWriter, r *http.Request)
- type BasicProblem
- type InternalProblem
- type Problem
- type RequestDecoratableProblem
- type ValidationProblem
- func (problem *ValidationProblem) Append(reasons ...ValidationReason)
- func (problem *ValidationProblem) AppendWithPrefix(prefix string, reasons ...ValidationReason)
- func (problem ValidationProblem) Error() string
- func (problem *ValidationProblem) Errors() (errors []error)
- func (problem *ValidationProblem) Merge(prefix string, err error)
- func (problem ValidationProblem) TrimEmpty() Problem
- type ValidationReason
Constants ¶
View Source
const ContentType = "application/problem+json"
Variables ¶
This section is empty.
Functions ¶
func WriteResponse ¶
WriteResponse, converts the error into a Problem and writes the contents into w. The Problem will be decorated with request information and logged if possible.
Types ¶
type BasicProblem ¶
type BasicProblem struct { // Type, a URI reference that identifies the problem type. // When dereferenced this should provide human-readable documentation for the // problem type. When member is not present it is assumed to be "about:blank". Type string `json:"type" format:"url"` // Title, a short, human-readable summary of the problem type. // This should always be the same value for the same Type. Title string `json:"title"` // Status, the HTTP status code associated with this problem occurrence. Status int `json:"status,omitempty"` // Detail, a human-readable explanation specific to this occurrence of the problem. Detail string `json:"detail,omitempty"` // Instance, a URI reference that identifies the specific resource on which the problem occurred. Instance string `json:"instance,omitempty" format:"url"` // CorrelationID, an unique identifier for tracing this issue in server logs. CorrelationID string `json:"correlationId,omitempty"` }
BasicProblem, common fields for most Problems. Useful for embedding into for custom problem types.
func (*BasicProblem) DecorateWithRequest ¶
func (problem *BasicProblem) DecorateWithRequest(ctx context.Context, r *http.Request)
func (BasicProblem) Error ¶
func (problem BasicProblem) Error() string
func (BasicProblem) ProblemStatus ¶
func (problem BasicProblem) ProblemStatus() int
func (BasicProblem) ProblemTitle ¶
func (problem BasicProblem) ProblemTitle() string
func (BasicProblem) ProblemType ¶
func (problem BasicProblem) ProblemType() string
type InternalProblem ¶
type InternalProblem struct { BasicProblem // contains filtered or unexported fields }
func Internal ¶
func Internal(cause error) InternalProblem
func (InternalProblem) Error ¶
func (problem InternalProblem) Error() string
func (InternalProblem) Unwrap ¶
func (problem InternalProblem) Unwrap() error
type Problem ¶
type Problem interface { error // ProblemType, a URI reference that identifies the problem type. // When dereferenced this should provide human-readable documentation for the // problem type. When member is not present it is assumed to be "about:blank". ProblemType() string // ProblemTitle, a short, human-readable summary of the problem type. // This should always be the same value for the same Type. ProblemTitle() string // ProblemStatus, the HTTP status code associated with this problem occurrence. // If the problem returns 0, it will be set to http.StatusInternalServerError. ProblemStatus() int }
Problem, basic interface for all errors supporting https://tools.ietf.org/html/rfc7807.
type ValidationProblem ¶
type ValidationProblem struct { BasicProblem Reasons []ValidationReason `json:"reasons,omitempty"` }
func Validation ¶
func Validation(reasons ...ValidationReason) ValidationProblem
func (*ValidationProblem) Append ¶
func (problem *ValidationProblem) Append(reasons ...ValidationReason)
func (*ValidationProblem) AppendWithPrefix ¶
func (problem *ValidationProblem) AppendWithPrefix(prefix string, reasons ...ValidationReason)
func (ValidationProblem) Error ¶ added in v0.13.1
func (problem ValidationProblem) Error() string
func (*ValidationProblem) Errors ¶
func (problem *ValidationProblem) Errors() (errors []error)
func (*ValidationProblem) Merge ¶
func (problem *ValidationProblem) Merge(prefix string, err error)
func (ValidationProblem) TrimEmpty ¶
func (problem ValidationProblem) TrimEmpty() Problem
type ValidationReason ¶
type ValidationReason struct { Name string `json:"name"` Reason string `json:"reason"` Cause error `json:"-"` }
func (ValidationReason) Error ¶
func (err ValidationReason) Error() string
Click to show internal directories.
Click to hide internal directories.