types

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2024 License: EUPL-1.2 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const ErrorContentType = "application/problem+json; charset=utf-8"

ErrorContentType is used as the content type when sending an error response

Variables

This section is empty.

Functions

This section is empty.

Types

type Scope

type Scope uint8
const (
	ScopeRead Scope = iota
	ScopeWrite
	ScopeDelete
	ScopeAdmin
)

func (Scope) String

func (s Scope) String() string

type ServiceError

type ServiceError struct {
	// Type contains a URI reference that identifies the problem type. This
	// identifier should be used as primary identifier and may point to an
	// external resource.
	//
	// See more: https://datatracker.ietf.org/doc/html/rfc9457#section-3.1.1
	Type string

	// Status contains the HTTP Status Code as defined in [RFC 9110]
	//
	// [RFC 9110]: https://www.rfc-editor.org/rfc/rfc9110#section-15
	Status uint

	// Title contains a short, human-readable summary of the problem (e.g.
	// Missing Authorization Information)
	Title string

	// Detail contains a human-readable description of the problem type while
	// focusing on problem correction instead of debugging
	Detail string

	// Instance contains a (possibly dereferenceable) URI which identifies the
	// specific occurrence of the error
	Instance string

	// Errors is an extension member that contains one or multiple error objects
	// which will be transformed into plain strings using the error interface
	Errors []error

	// Host contains the hostname of the server the error occurred on
	Host string
}

ServiceError is the commonly used error response in the WISdoM environment. It implements RFC 9457 to enable an easy usage of the error responses in other systems.

It contains the following extension members

  • Errors: []error
  • Host: string

The Host field is automatically filled during the marshaling of the error into an JSON object

func (*ServiceError) Equals

func (se *ServiceError) Equals(other ServiceError) bool

Equals checks if the current WISdoMError object is equal to the provided ServiceError object. It compares the values of the Type, Status, Title, and Detail fields between the two objects. If any of these fields differ, Equals returns false. Otherwise, it returns true, indicating that the two objects are equal.

Example usage:

err1 := &ServiceError{
    Type:   "error",
    Status: 500,
    Title:  "Internal Server Error",
    Detail: "An unknown error occurred",
}
err2 := &ServiceError{
    Type:   "error",
    Status: 500,
    Title:  "Internal Server Error",
    Detail: "An unknown error occurred",
}
equal := err1.Equals(*err2)
fmt.Println(equal) // Output: true

func (ServiceError) MarshalJSON

func (se ServiceError) MarshalJSON() ([]byte, error)

MarshalJSON is used to change the serialization of the Errors

func (*ServiceError) Send

func (se *ServiceError) Send(w http.ResponseWriter)

Send transmits the error using the supplied http.ResponseWriter

func (*ServiceError) SetInstance

func (se *ServiceError) SetInstance() error

SetInstance generates a URI of the TAG format containing a unique identifier for this error and assignes it to the Instance field

Jump to

Keyboard shortcuts

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