forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_codes.go
52 lines (46 loc) · 1.17 KB
/
error_codes.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
package types
import (
"net/http"
"strconv"
)
// From JSONRPC 2.0 spec
type RPCErrorCode int
const (
RPCErrorCodeParseError RPCErrorCode = -32700
RPCErrorCodeInvalidRequest RPCErrorCode = -32600
RPCErrorCodeMethodNotFound RPCErrorCode = -32601
RPCErrorCodeInvalidParams RPCErrorCode = -32602
RPCErrorCodeInternalError RPCErrorCode = -32603
RPCErrorCodeServerError RPCErrorCode = -32000
)
func (code RPCErrorCode) String() string {
switch code {
case RPCErrorCodeParseError:
return "Parse Error"
case RPCErrorCodeInvalidRequest:
return "Parse Error"
case RPCErrorCodeMethodNotFound:
return "Method Not Found"
case RPCErrorCodeInvalidParams:
return "Invalid Params"
case RPCErrorCodeInternalError:
return "Internal Error"
case RPCErrorCodeServerError:
return "Server Error"
default:
return strconv.FormatInt(int64(code), 10)
}
}
func (code RPCErrorCode) HTTPStatusCode() int {
switch code {
case RPCErrorCodeInvalidRequest:
return http.StatusBadRequest
case RPCErrorCodeMethodNotFound:
return http.StatusMethodNotAllowed
default:
return http.StatusInternalServerError
}
}
func (code RPCErrorCode) Error() string {
return code.String()
}