Skip to content

save95/xerror

Repository files navigation

xerror

错误码处理包:包含基础的错误处理

Usage

基本用法

package examples

import (
	"fmt"

	"github.com/save95/xerror"
	"github.com/save95/xerror/xcode"
)

func ExampleNew() {
	err := xerror.New("whoops")
	fmt.Println(err)
	fmt.Println(err.HttpStatus())
	fmt.Println(err.ErrorCode())

	// Output: whoops
	// 500
	// 500
}

func ExampleWithCode() {
	code := 1001
	err := xerror.WithCode(code, "server error message")
	fmt.Println(err)
	fmt.Println(err.HttpStatus())
	fmt.Println(err.ErrorCode())

	// Output:
	// server error message
	// 500
	// 1001
}

func ExampleWithXCode() {
	err := xerror.WithXCode(xcode.InternalServerError)
	fmt.Println(err)

	// Output:
	// 内部服务错误
}

更多用法请访问 错误码基本使用场景

其他用法

License

MIT License