Create a http error
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",
},
}
he := New("error message")
he := NewWithCaller("error message")
Get the description of http error
he := &Error{
Message: "error message",
Code: "cus-validate-fail",
Category: "common",
}
// category=common, code=cus-validate-fail, message=error message
fmt.Println(he.Error())
Error format
he := &Error{
Message: "error message",
Code: "cus-validate-fail",
Category: "common",
}
Set the caller of error
he := &Error{
Message: "error message",
Code: "cus-validate-fail",
Category: "common",
}
he.SetCaller(1)
Error to json
he := &Error{
Message: "error message",
Code: "cus-validate-fail",
Category: "common",
}
he.ToJSON()
Enable or disable to get caller by default
EnableCaller(true);
EnableCaller(false);