aselerror

package module
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 1 Imported by: 0

README

English

aselerror

aselerror 是一个专门处理“异常API接口响应”的错误处理包。

在传统的响应处理中,我们通常需要判断错误信息是否敏感,然后才能决定是否返回给前端。频繁使用ifswitch语句可能不是最佳选择。 aselerror可以通过比较错误等级来简化这一过程,从而显著减少接口响应时间。

注意事项

  • 由于aselerror设计较为简单,建议与errors包结合使用以获取堆栈信息。
  • aselerror主要用于处理异常API接口响应。在正常情况下,建议避免使用它,因为错误信息应保持简洁明了。

安装

go get github.com/Locter9001/aselerror

使用

请查看 error_test.go 文件 => error_test.go

Documentation

Overview

Package aselerror

这是一个自定义封装的错误处理包,相比原本的 errors 包它有错误代码和灾害等级。

将它用于常见的API系统是最佳的实现,因为在这种系统中我们有时候需要过滤错误,
不能让所有错误都返回到前端,比起使用swich遍历不如直接比较灾害等级之后设置回调消息来得更方便。

- 这个包设计相对比较简单,因此推荐配合 errors 使用,这样还能有堆栈信息。
- aselerror的设计理念就是针对API接口,正常情况下建议请避免使用它

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AselError

type AselError interface {
	GetCode() int
	GetLevel() int8
	GetMessage() string
	Error() string
	SetMessage(msg string) AselError
	SetFMessage(format string, a ...interface{}) AselError
	SetCause(err error) AselError
}

func New

func New(message string, opts ...AselOption) AselError

func Wrap

func Wrap(err error, message string) AselError

type AselOption

type AselOption func(*aerr)

func WithCause

func WithCause(err error) AselOption

func WithCode

func WithCode(code int) AselOption

func WithLevel

func WithLevel(level int8) AselOption

Jump to

Keyboard shortcuts

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