ose_error

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: MIT Imports: 7 Imported by: 1

README

ose-error

ose-error is a structured and reusable Go error package for building microservices and APIs. It provides:

Go Reference Go Report Card License

  • Structured error types with codes and messages
  • Error wrapping for context
  • Validation errors support
  • gRPC and HTTP error mapping
  • Clean/sanitized errors for API clients

It’s designed to work seamlessly across microservices, keeping error handling consistent and maintainable.


Installation

go get github.com/ose-micro/error

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

func GRPCErrorWithTrace

func GRPCErrorWithTrace(ctx context.Context, err *Error) (context.Context, error)

func HTTPCodeToGRPCCode

func HTTPCodeToGRPCCode(httpCode Code) codes.Code

func Is

func Is(err, target error) bool

func ToGRPCError

func ToGRPCError(err *Error) error

Types

type Code

type Code int
const (
	ErrInternalServerError Code = 500
	ErrBadRequest          Code = 400
	ErrNotFound            Code = 404
	ErrUnauthorized        Code = 401
	ErrForbidden           Code = 403
	ErrUnprocessableEntity Code = 422
	ErrTooManyRequests     Code = 429
	ErrConflict            Code = 409
	ErrServiceUnavailable  Code = 503
	ErrBadGateway          Code = 502
	ErrGatewayTimeout      Code = 504
)

func GRPCCodeToHTTPCode

func GRPCCodeToHTTPCode(grpcCode codes.Code) Code

func (Code) Equal

func (c Code) Equal(code Code) bool

func (Code) String

func (c Code) String() string

type Error

type Error struct {
	// contains filtered or unexported fields
}

func CastToError

func CastToError(err error) *Error

func CastToErrorSafe added in v0.0.2

func CastToErrorSafe(err error) (*Error, bool)

func Clean

func Clean(err error) *Error

Clean converts any error into a clean *Error struct

func FromGRPCError

func FromGRPCError(err error) *Error

func New

func New(code Code, message string, traceId ...string) *Error

func Unwrap

func Unwrap(err error) *Error

func Wrap

func Wrap(err error, code Code, message string, traceId ...string) *Error

func (*Error) Code

func (e *Error) Code() Code

func (*Error) Err

func (e *Error) Err() error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Message

func (e *Error) Message() string

func (*Error) Status

func (e *Error) Status() int

func (*Error) Unwrap

func (e *Error) Unwrap() error

Jump to

Keyboard shortcuts

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