catcher

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: MIT Imports: 9 Imported by: 30

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SdkError

type SdkError struct {
	Code  string         `json:"code"`
	Trace []string       `json:"trace"`
	Msg   string         `json:"msg"`
	Cause *string        `json:"cause,omitempty"`
	Args  map[string]any `json:"args,omitempty"`
}

SdkError is a struct that implements the Go error interface.

func Error

func Error(msg string, cause error, args map[string]any) *SdkError

Error tries to cast the cause as an SdkError, if it is not an SdkError, it creates a new SdkError with the given parameters. It logs the error message and returns the error. If cause is nil, it will store a blank string in the Cause field. The field Code is a hash of the message and trace. It is used to identify the recurrence of an error. Params: msg: the error message. cause: the error that caused this error. args: a map of additional information. Returns: *SdkError: the error. This type implements the Go error interface.

func ToSdkError

func ToSdkError(err error) *SdkError

ToSdkError tries to cast an error to a SdkError. If the error is not an SdkError, it returns nil.

func (SdkError) Error

func (e SdkError) Error() string

Error returns the error message.

func (SdkError) GinError

func (e SdkError) GinError(c *gin.Context)

GinError is a helper function to return an error to the client using Gin framework context. It sets the headers x-error and x-error-id with the error message and UUID respectively and sets the status code.

Jump to

Keyboard shortcuts

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