package handler import ( "github.com/google/uuid" "github.com/pkg/errors" pb "go.unistack.org/unistack-org/pkgdash/proto" ) const ( badRequest = `Bad Requet` internalError = `Internal Error` notFound = `Source Not Found` ) const ( internalErrorCode = "1" badRequestCode = "2" notFoundErrorCode = "3" ) type UnmarshalError struct { err error } func (e *UnmarshalError) Error() string { return e.err.Error() } func (e *UnmarshalError) Unwrap() error { return e.err } func NewUnmarshalError(err error) error { return errors.WithStack(&UnmarshalError{err: err}) } func NewInternalError(err error) *pb.ErrorRsp { return &pb.ErrorRsp{ Error: &pb.Error{ Code: internalErrorCode, Title: internalError, Uuid: uuid.New().String(), Details: err.Error(), }, } } type ParametersMissingError struct { Err error } func (e *ParametersMissingError) Error() string { return e.Err.Error() } func NewParametersMissingError(err error) error { return errors.WithStack(&ParametersMissingError{Err: err}) } func NewNotFoundError(err error) *pb.ErrorRsp { return &pb.ErrorRsp{ Error: &pb.Error{ Code: notFoundErrorCode, Title: notFound, Uuid: uuid.New().String(), Details: err.Error(), }, } } func NewValidationError(err error) *pb.ErrorRsp { return &pb.ErrorRsp{ Error: &pb.Error{ Code: badRequestCode, Title: badRequest, Uuid: uuid.New().String(), Details: err.Error(), }, } }