-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.go
More file actions
30 lines (23 loc) · 852 Bytes
/
example.go
File metadata and controls
30 lines (23 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"net/http"
e "github.com/SwellNetwork/go-error/pkg/error"
"github.com/SwellNetwork/go-error/pkg/transformer"
)
const (
ErrCodeCustomized = "CUSTOMIZED"
ErrMsgCustomized = "Customized error"
ClientErrCodeCustomized = 40099
ClientErrMsgCustomized = "Customized client error"
)
func NewErrCustomized(rootCause error, entities ...string) *e.Error {
return e.NewError(ErrCodeCustomized, ErrMsgCustomized, entities, rootCause)
}
func NewRestAPIErrCustomized(rootCause error, entities ...string) *e.RestAPIError {
message := e.AppendEntitiesToErrMsg(ClientErrMsgCustomized, entities)
return e.NewRestAPIError(http.StatusBadRequest, ClientErrCodeCustomized, message, entities, rootCause)
}
func main() {
t := transformer.RestTransformerInstance()
t.RegisterTransformFunc(ErrCodeCustomized, NewRestAPIErrCustomized)
}