Skip to content

Latest commit

 

History

History
82 lines (56 loc) · 2.51 KB

File metadata and controls

82 lines (56 loc) · 2.51 KB

errorResponses

import "github.com/greenbone/opensight-golang-libraries/pkg/errorResponses"

Package errorResponses provides rest api models for errors

Index

Constants

const (
    ErrorTypeGeneric     = errorTypePrefix + "generic-error"
    ErrorTypeValidation  = errorTypePrefix + "validation-error"
    ErrorTypeUpstreamApi = errorTypePrefix + "upstream-api-error"
    ErrorTypeApi         = errorTypePrefix + "api-error"
    ErrorTypeConnection  = errorTypePrefix + "connection-error"
)

Variables

var ErrorInternalResponse = ErrorResponse{
    Type:  ErrorTypeGeneric,
    Title: "internal error",
}

type ErrorResponse struct {
    Type    string            `json:"type"`
    Title   string            `json:"title"`
    Details string            `json:"details,omitempty"`
    Errors  map[string]string `json:"errors,omitempty"`
}

func NewErrorGenericResponse(message ...any) ErrorResponse

NewErrorGenericResponse returns a ErrorResponse of type Generic with the given error message. The message is handled the same as fmt.Println.

func NewErrorValidationResponse(title, details string, errors map[string]string) ErrorResponse

NewErrorValidationResponse returns a ErrorResponse of type Validation. `errors` is a mapping from field name to error message for this specific field.

Generated by gomarkdoc