errorResponses

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: GPL-3.0 Imports: 1 Imported by: 2

README

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

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
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
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

Documentation

Overview

Package errorResponses provides rest api models for errors

Index

Constants

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

Variables

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

Functions

This section is empty.

Types

type ErrorResponse

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

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

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.

Jump to

Keyboard shortcuts

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