forked from FactomProject/factomd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
errors.go
99 lines (90 loc) · 4.08 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2017 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package wsapi
import (
"github.com/FactomProject/factomd/common/primitives"
)
/*
The error codes from and including -32768 to -32000 are reserved for pre-defined errors.
Any code within this range, but not defined explicitly below is reserved for future use.
The error codes are nearly the same as those suggested for XML-RPC at the following url:
http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
code message meaning
-32700 Parse error Invalid JSON was received by the server.
An error occurred on the server while parsing the JSON text.
-32600 Invalid Request The JSON sent is not a valid Request object.
-32601 Method not found The method does not exist / is not available.
-32602 Invalid params Invalid method parameter(s).
-32603 Internal error Internal JSON-RPC error.
-32000 to -32099 Server error Reserved for implementation-defined server-errors.
*/
func NewParseError() *primitives.JSONError {
return primitives.NewJSONError(-32700, "Parse error", nil)
}
func NewInvalidRequestError() *primitives.JSONError {
return primitives.NewJSONError(-32600, "Invalid Request", nil)
}
func NewMethodNotFoundError() *primitives.JSONError {
return primitives.NewJSONError(-32601, "Method not found", nil)
}
func NewInvalidParamsError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", nil)
}
func NewInternalError() *primitives.JSONError {
return primitives.NewJSONError(-32603, "Internal error", nil)
}
/*******************************************************************/
func NewCustomInternalError(data interface{}) *primitives.JSONError {
return primitives.NewJSONError(-32603, "Internal error", data)
}
func NewCustomInvalidParamsError(data interface{}) *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", data)
}
/*******************************************************************/
func NewInvalidAddressError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", "Invalid Address")
}
func NewUnableToDecodeTransactionError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", "Unable to decode the transaction")
}
func NewInvalidTransactionError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", "Invalid Transaction")
}
func NewInvalidHashError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", "Invalid Hash")
}
func NewInvalidEntryError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", "Invalid Entry")
}
func NewInvalidCommitChainError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", "Invalid Commit Chain")
}
func NewInvalidCommitEntryError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", "Invalid Commit Entry")
}
func NewInvalidDataPassedError() *primitives.JSONError {
return primitives.NewJSONError(-32602, "Invalid params", "Invalid data passed")
}
func NewInternalDatabaseError() *primitives.JSONError {
return primitives.NewJSONError(-32603, "Internal error", "database error")
}
//http://www.jsonrpc.org/specification : -32000 to -32099 error codes are reserved for implementation-defined server-errors.
func NewBlockNotFoundError() *primitives.JSONError {
return primitives.NewJSONError(-32008, "Block not found", nil)
}
func NewEntryNotFoundError() *primitives.JSONError {
return primitives.NewJSONError(-32008, "Entry not found", nil)
}
func NewObjectNotFoundError() *primitives.JSONError {
return primitives.NewJSONError(-32008, "Object not found", nil)
}
func NewMissingChainHeadError() *primitives.JSONError {
return primitives.NewJSONError(-32009, "Missing Chain Head", nil)
}
func NewReceiptError() *primitives.JSONError {
return primitives.NewJSONError(-32010, "Receipt creation error", nil)
}
func NewRepeatCommitError(data interface{}) *primitives.JSONError {
return primitives.NewJSONError(-32011, "Repeated Commit", data)
}