This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
errors.go
83 lines (73 loc) · 2.19 KB
/
errors.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
72
73
74
75
76
77
78
79
80
81
82
83
package errors
import (
"fmt"
"github.com/ronaksoft/rony"
)
/*
Creation Time: 2021 - May - 21
Created by: (ehsan)
Maintainers:
1. Ehsan N. Moosa (E2)
Auditor: Ehsan N. Moosa (E2)
Copyright Ronak Software Group 2020
*/
func New(code Code, item string) *rony.Error {
return &rony.Error{
Code: string(code),
Items: item,
Description: "",
}
}
func NewF(code Code, item string, format string, args ...interface{}) *rony.Error {
return &rony.Error{
Code: string(code),
Items: item,
Description: fmt.Sprintf(format, args...),
}
}
func Message(reqID uint64, errCode Code, errItem string) *rony.MessageEnvelope {
msg := &rony.MessageEnvelope{}
ToMessage(msg, reqID, errCode, errItem)
return msg
}
func ToMessage(out *rony.MessageEnvelope, reqID uint64, errCode Code, errItem string) {
errMessage := rony.PoolError.Get()
errMessage.Code = string(errCode)
errMessage.Items = errItem
out.Fill(reqID, rony.C_Error, errMessage)
rony.PoolError.Put(errMessage)
}
var (
GenAccessErr = genWithErrorAndItem(Access)
GenAlreadyExistsErr = genWithErrorAndItem(AlreadyExists)
GenBusyErr = genWithErrorAndItem(Busy)
GenExpiredErr = genWithErrorAndItem(Expired)
GenIncompleteErr = genWithErrorAndItem(Incomplete)
GenInternalErr = genWithErrorAndItem(Internal)
GenInvalidErr = genWithErrorAndItem(Invalid)
GenNotImplementedErr = genWithErrorAndItem(NotImplemented)
GenOutOfRangeErr = genWithErrorAndItem(OutOfRange)
GenPartiallyAppliedErr = genWithErrorAndItem(PartiallyApplied)
GenTimeoutErr = genWithErrorAndItem(Timeout)
GenTooFewErr = genWithErrorAndItem(TooFew)
GenTooManyErr = genWithErrorAndItem(TooMany)
GenUnavailableErr = genWithErrorAndItem(Unavailable)
)
func genWithErrorAndItem(code Code) func(item string, err error) *rony.Error {
codeString := string(code)
return func(item string, err error) *rony.Error {
if err != nil {
return &rony.Error{
Code: codeString,
Items: item,
Description: err.Error(),
}
} else {
return &rony.Error{
Code: codeString,
Items: item,
Description: "",
}
}
}
}