Documentation
¶
Index ¶
- Constants
- func Err(code string, msg string, httpCode int) error
- func ErrDataNotFound() error
- func ErrInvHeader(msg ...string) error
- func ErrInvRule(msg ...string) error
- func ErrNotFound(msg ...string) error
- func ErrParam(msg ...string) error
- func ErrPermission(msg ...string) error
- func ErrRuntime(msg ...string) error
- func ErrThirdParty(msg ...string) error
- func ErrUnsupported(msg ...string) error
- func ErrValidation(msg string, validation []string) error
- func ErrWaiting(msg ...string) error
- func GetCode(e error) string
- func GetHttpCode(e error) int
- func GetMeta(e error) any
- func GetMsg(e error) string
- func GetStackTrace(e error) string
- func GetValidationErrorMsg(e error) []string
- func IsErrNotFound(e error) bool
- func IsStdError(e error) bool
- func RemoveDebugDepthLevel()
- func SetDebugDepthLevel(lvl int)
Constants ¶
const ( ERROR_CODE_INVALID_HEADER = "X0" ERROR_CODE_ACCESS_PERMISSION = "X1" ERROR_CODE_PARAMETER = "01" // 200, mostly in controller when failed in validation rules ERROR_CODE_DATA_NOT_FOUND = "02" ERROR_CODE_INVALID_RULE = "03" ERROR_CODE_THIRD_PARTY = "04" ERROR_CODE_WAITING_STATUS = "05" ERROR_CODE_UNSUPPORTED = "06" ERROR_CODE_SYSTEM = "99" // 200, e.g. failed in connection )
The standard error codes that is used in brispot.
const ( ERROR_DESC_INVALID_HEADER = "Header request tidak valid" ERROR_DESC_PERMISSION = "Akses tidak diijinkan" ERROR_DESC_PARAMETER = "Parameter tidak sesuai" ERROR_DESC_DATA_NOT_FOUND = "Data tidak ditemukan" ERROR_DESC_INVALID_RULE = "Validasi rule tidak terpenuhi" ERROR_DESC_THIRD_PARTY = "Service ThirdParty bermasalah" ERROR_DESC_WAITING_STATUS = "Masih proses harap tunggu" ERROR_DESC_UNSUPPORTED = "Mekanisme tidak disupport" ERROR_DESC_SYSTEM = "Runtime error happens" )
The standard error description that is used in brispot.
Variables ¶
This section is empty.
Functions ¶
func Err ¶
Err set std error by given error code, message and any desired http code.
Each value can be retrieved by helper func such as GetCode, GetMsg, GetMeta.
func ErrDataNotFound ¶
func ErrDataNotFound() error
ErrDataNotFound error similar with ErrNotFound but use message 'data tidak ditemukan'.
func ErrInvHeader ¶
ErrInvHeader error invalid header, this may commonly be used in spotlibs gateway.
This error will set the response http code to 400 via stdresp.WithErr.
func ErrInvRule ¶
ErrInvRule any process that does not meet with the requirement set in the usecase layer.
func ErrNotFound ¶
ErrNotFound error when the 'expected' data not found, this may exist in both usecase and repository layer, or even in the service layer.
func ErrPermission ¶
ErrPermission error permission denied, this may commonly be used in api gateway, or any other middleware that need to return non-200 http status code.
This error will set the response http code to 403 via stdresp.WithErr.
func ErrRuntime ¶
ErrRuntime unexpected error that may occur in the runtime.
e.g. error when doing json Marshal/Unmarshal.
func ErrThirdParty ¶
ErrThirdParty error triggered by surrounding service. It's up to developer whether they should propagate the 'error' from surrounding to the response, or to masking it and mark it as 3rd-party error.
func ErrUnsupported ¶
ErrUnsupported error when the incoming request can not be supported.
e.g. when incoming request with method GET but the endpoint expect POST.
func ErrValidation ¶
ErrValidation error in validation, it's not recommended to be used directly.
Currently, this func only used by validation pkg.
func ErrWaiting ¶
ErrWaiting error when there is still process occurring in the background.
func GetCode ¶
GetCode get the error code if the given error if it's error coming from this stderr pkg, otherwise will return the default ERROR_CODE_SYSTEM.
func GetHttpCode ¶
GetHttpCode get the http status code reside in the error. Will return the correct http code if the error coming from this stderr pkg, otherwise will return 500.
func GetMeta ¶
GetMeta get the error metadata if the given error is coming from this stderr pkg, otherwise will return nil.
func GetMsg ¶
GetMsg get the error message if the given error if it's error coming from this pkg, otherwise will return the default ERROR_DESC_SYSTEM.
func GetStackTrace ¶
GetStackTrace get the error stack trace if the given error if it's error coming from this pkg, otherwise will return the default ERROR_DESC_SYSTEM.
func GetValidationErrorMsg ¶
GetValidationErrorMsg return the validation message injected in ErrValidation, otherwise will just return nil.
func IsErrNotFound ¶
IsErrNotFound return true if the given error is created using ErrNotFound or ErrDataNotFound.
func IsStdError ¶
IsStdError check whether given error is created using this stderr pkg.
func RemoveDebugDepthLevel ¶
func RemoveDebugDepthLevel()
RemoveDebugDepthLevel remove the depth level so that error will print all captured stack trace.
func SetDebugDepthLevel ¶
func SetDebugDepthLevel(lvl int)
SetDebugDepthLevel set the depth level of line captured in the debug.
Types ¶
This section is empty.