github.com/vicanso/hes@v0.7.0/README.md (about) 1 # hes 2 3 [![Build Status](https://github.com/vicanso/hes/workflows/Test/badge.svg)](https://github.com/vicanso/hes/actions) 4 5 6 7 Create a http error 8 9 # API 10 11 ## HTTP Error 12 13 ```go 14 err := errors.New("abcd") 15 he := &Error{ 16 StatusCode: 500, 17 Code: "cus-validate-fail", 18 Category: "comon", 19 Message: err.Error(), 20 Err: err, 21 Exception: true, 22 Extra: map[string]interface{}{ 23 "url": "http:///127.0.0.1/users/me", 24 }, 25 } 26 ``` 27 28 ```go 29 he := New("error message") 30 ``` 31 32 ```go 33 he := NewWithCaller("error message") 34 ``` 35 36 ### Error 37 38 Get the description of http error 39 40 ```go 41 he := &Error{ 42 Message: "error message", 43 Code: "cus-validate-fail", 44 Category: "common", 45 } 46 // category=common, code=cus-validate-fail, message=error message 47 fmt.Println(he.Error()) 48 ``` 49 50 ### Format 51 52 Error format 53 54 ```go 55 he := &Error{ 56 Message: "error message", 57 Code: "cus-validate-fail", 58 Category: "common", 59 } 60 ``` 61 62 ### SetCaller 63 64 Set the caller of error 65 66 ```go 67 he := &Error{ 68 Message: "error message", 69 Code: "cus-validate-fail", 70 Category: "common", 71 } 72 he.SetCaller(1) 73 ``` 74 75 ### ToJSON 76 77 Error to json 78 79 ```go 80 he := &Error{ 81 Message: "error message", 82 Code: "cus-validate-fail", 83 Category: "common", 84 } 85 he.ToJSON() 86 ``` 87 88 ## EnableCaller 89 90 Enable or disable to get caller by default 91 92 ```go 93 EnableCaller(true); 94 EnableCaller(false); 95 ```