https://github.com/vicanso/hes
custom errors
https://github.com/vicanso/hes
error httperror
Last synced: 4 months ago
JSON representation
custom errors
- Host: GitHub
- URL: https://github.com/vicanso/hes
- Owner: vicanso
- License: apache-2.0
- Created: 2018-12-19T05:18:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-03T12:06:48.000Z (about 1 year ago)
- Last Synced: 2025-05-18T10:07:15.160Z (about 1 year ago)
- Topics: error, httperror
- Language: Go
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hes
[](https://github.com/vicanso/hes/actions)
Create a http error
# API
## HTTP Error
```go
err := errors.New("abcd")
he := &Error{
StatusCode: 500,
Code: "cus-validate-fail",
Category: "comon",
Message: err.Error(),
Err: err,
Exception: true,
Extra: map[string]interface{}{
"url": "http:///127.0.0.1/users/me",
},
}
```
```go
he := New("error message")
```
```go
he := NewWithCaller("error message")
```
### Error
Get the description of http error
```go
he := &Error{
Message: "error message",
Code: "cus-validate-fail",
Category: "common",
}
// category=common, code=cus-validate-fail, message=error message
fmt.Println(he.Error())
```
### Format
Error format
```go
he := &Error{
Message: "error message",
Code: "cus-validate-fail",
Category: "common",
}
```
### SetCaller
Set the caller of error
```go
he := &Error{
Message: "error message",
Code: "cus-validate-fail",
Category: "common",
}
he.SetCaller(1)
```
### ToJSON
Error to json
```go
he := &Error{
Message: "error message",
Code: "cus-validate-fail",
Category: "common",
}
he.ToJSON()
```
## EnableCaller
Enable or disable to get caller by default
```go
EnableCaller(true);
EnableCaller(false);
```