Skip to content

errors ​

go
import "github.com/prescriptoo/prescriptoo-api/pkg/errors"

Package errors provides standard domain error types across microservices.

Index ​

func HTTPStatusCode ​

go
func HTTPStatusCode(code Code) int

HTTPStatusCode maps domain error code to HTTP status code.

type AppError ​

AppError is a structured error containing code, message, and underlying error.

go
type AppError struct {
    Code    Code   `json:"code"`
    Message string `json:"message"`
    Err     error  `json:"-"`
}

func New ​

go
func New(code Code, message string, err error) *AppError

New creates a new AppError.

func (*AppError) Error ​

go
func (e *AppError) Error() string

func (*AppError) Unwrap ​

go
func (e *AppError) Unwrap() error

type Code ​

Code represents a domain error code.

go
type Code string

Error codes for common domain errors.

go
const (
    CodeNotFound      Code = "NOT_FOUND"
    CodeAlreadyExists Code = "ALREADY_EXISTS"
    CodeInvalidInput  Code = "INVALID_INPUT"
    CodeUnauthorized  Code = "UNAUTHORIZED"
    CodeForbidden     Code = "FORBIDDEN"
    CodeInternalError Code = "INTERNAL_ERROR"
)

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.