-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.go
71 lines (53 loc) · 2.03 KB
/
functions.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package berr
func FromError(err error) (*Error, bool) {
berrError, okay := err.(*Error)
return berrError, okay
}
func New(errorType ErrorType, message string, attachments ...*Attachment) *Error {
return newBerr(errorType, message, attachments...)
}
func Application(message string, attachments ...*Attachment) *Error {
return New(ApplicationErrorType, message, attachments...)
}
func ValueInvalid(message string, attachments ...*Attachment) *Error {
return New(ValueInvalidErrorType, message, attachments...)
}
func ValueMissing(message string, attachments ...*Attachment) *Error {
return New(ValueMissingErrorType, message, attachments...)
}
func Authorization(message string, attachments ...*Attachment) *Error {
return New(AuthorizationErrorType, message, attachments...)
}
func Authentication(message string, attachments ...*Attachment) *Error {
return New(AuthenticationErrorType, message, attachments...)
}
func NotFound(message string, attachments ...*Attachment) *Error {
return New(NotFoundErrorType, message, attachments...)
}
func Unimplemented(message string, attachments ...*Attachment) *Error {
return New(UnimplementedErrorType, message, attachments...)
}
func Conflict(message string, attachments ...*Attachment) *Error {
return New(ConflictErrorType, message, attachments...)
}
func Timeout(message string, attachments ...*Attachment) *Error {
return New(TimeoutErrorType, message, attachments...)
}
func Detail(key string, value any) *Attachment {
return &Attachment{attachmentType: AttachmentDetailType, key: key, value: value}
}
func D(key string, value any) *Attachment {
return Detail(key, value)
}
func Metadata(key string, value any) *Attachment {
return &Attachment{attachmentType: AttachmentMetadataType, key: key, value: value, sensitive: true}
}
func M(key string, value any) *Attachment {
return Metadata(key, value)
}
func Err(value error) *Attachment {
return &Attachment{attachmentType: AttachmentErrorType, key: "error", value: value, sensitive: true}
}
func E(value error) *Attachment {
return Err(value)
}