Skip to content

vicanso/hes

Repository files navigation

hes

Build Status

Create a http error

API

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")

Error

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())

Format

Error format

he := &Error{
  Message: "error message",
  Code: "cus-validate-fail",
  Category: "common",
}

SetCaller

Set the caller of error

he := &Error{
  Message: "error message",
  Code: "cus-validate-fail",
  Category: "common",
}
he.SetCaller(1)

ToJSON

Error to json

he := &Error{
  Message: "error message",
  Code: "cus-validate-fail",
  Category: "common",
}
he.ToJSON()

EnableCaller

Enable or disable to get caller by default

EnableCaller(true);
EnableCaller(false);