forked from FactomProject/FactomCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.go
More file actions
126 lines (96 loc) · 3.71 KB
/
error.go
File metadata and controls
126 lines (96 loc) · 3.71 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package common
import (
"fmt"
)
const (
ErrorBadMethod = 0
ErrorNotAcceptable = 1
ErrorMissingVersionSpec = 2
ErrorMalformedVersionSpec = 3
ErrorBadVersionSpec = 4
ErrorEmptyRequest = 5
ErrorBadElementSpec = 6
ErrorBadIdentifier = 7
ErrorBlockNotFound = 8
ErrorEntryNotFound = 9
ErrorInternal = 10
ErrorJSONMarshal = 11
ErrorXMLMarshal = 12
ErrorUnsupportedMarshal = 13
ErrorJSONUnmarshal = 14
ErrorXMLUnmarshal = 15
ErrorUnsupportedUnmarshal = 16
ErrorBadPOSTData = 17
ErrorTemplateError = 18
ErrorHTTPNewRequestFailure = 19
ErrorHTTPDoRequestFailure = 20
ErrorHTMLMarshal = 21
ErrorVerifySignature = 22
)
type Error struct {
APICode uint
HTTPCode int
Name string
Description string
SupportURL string
Message string
}
func (r *Error) Error() string {
return fmt.Sprint(r.Name, "\n", r.Description, "\n", r.Message)
}
func CreateError(code uint, message string) *Error {
r := new(Error)
r.APICode = code
r.HTTPCode, r.Name, r.Description, r.SupportURL = retreiveErrorParameters(code)
r.Message = message
return r
}
func retreiveErrorParameters(code uint) (int, string, string, string) {
switch code {
case ErrorInternal:
return 500, "Internal", "An internal error occured", ""
case ErrorJSONMarshal:
return 500, "JSON Marshal", "An error occured marshalling into JSON", ""
case ErrorXMLMarshal:
return 500, "XML Marshal", "An error occured marshalling into XML", ""
case ErrorUnsupportedMarshal:
return 500, "Unsupported Marshal", "The server attempted to marshal the data into an unsupported format", ""
case ErrorBadMethod:
return 405, "Bad Method", "The specified method cannot be used on the specified resource", ""
case ErrorNotAcceptable:
return 406, "Not Acceptable", "The resource cannot be retreived as any of the acceptable types", ""
case ErrorMissingVersionSpec:
return 400, "Missing Version Spec", "The API version specifier is missing from the request URL", ""
case ErrorMalformedVersionSpec:
return 400, "Malformed Version Spec", "The API version specifier is malformed", ""
case ErrorBadVersionSpec:
return 400, "Bad Version Spec", "The API version specifier specifies a bad version", ""
case ErrorEmptyRequest:
return 200, "Empty Request", "The request is empty", ""
case ErrorBadElementSpec:
return 400, "Bad Element Spec", "The element specifier is bad", ""
case ErrorBadIdentifier:
return 400, "Bad Identifier", "The element identifier was malformed", ""
case ErrorBlockNotFound:
return 404, "Block Not Found", "The specified block cannot be found", ""
case ErrorEntryNotFound:
return 404, "Entry Not Found", "The specified entry cannot be found", ""
case ErrorJSONUnmarshal:
return 400, "JSON Unmarshal", "An error occured while unmarshalling from JSON", ""
case ErrorXMLUnmarshal:
return 400, "XML Unmarshal", "An error occured while unmarshalling from XML", ""
case ErrorUnsupportedUnmarshal:
return 400, "Unsupported Unmarshal", "The data was specified to be in an unsupported format", ""
case ErrorBadPOSTData:
return 400, "Bad POST Data", "The body of the POST request is malformed", ""
case ErrorTemplateError:
return 500, "Template Error", "A template error occured", ""
case ErrorHTTPNewRequestFailure:
return 500, "HTTP Request Failure", "Failed to create an HTTP request", ""
case ErrorHTTPDoRequestFailure:
return 500, "HTTP Request Failure", "Error while executing an HTTP request", ""
case ErrorHTMLMarshal:
return 500, "HTML Marshal", "An error occured marshalling into HTML", ""
}
return 500, "Unknown Error", "An unknown error occured", ""
}