|
| 1 | +""" |
| 2 | + JSONRPCError |
| 3 | +
|
| 4 | +An object representing a JSON-RPC Error. |
| 5 | +
|
| 6 | +Fields: |
| 7 | + * code::Int |
| 8 | + * msg::AbstractString |
| 9 | + * data::Any |
| 10 | +
|
| 11 | +See Section 5.1 of the JSON RPC 2.0 specification for more information. |
| 12 | +""" |
1 | 13 | struct JSONRPCError <: Exception |
2 | 14 | code::Int |
3 | 15 | msg::AbstractString |
4 | 16 | data::Any |
5 | 17 | end |
6 | 18 |
|
| 19 | +""" |
| 20 | + PARSE_ERROR |
| 21 | +
|
| 22 | +Invalid JSON was received by the server. |
| 23 | +An error occurred on the server while parsing the JSON text. |
| 24 | +""" |
| 25 | +const PARSE_ERROR = -32700 |
| 26 | + |
| 27 | +""" |
| 28 | + INVALID_REQUEST |
| 29 | +
|
| 30 | +The JSON sent is not a valid Request object. |
| 31 | +""" |
| 32 | +const INVALID_REQUEST = -32600 |
| 33 | + |
| 34 | +""" |
| 35 | + METHOD_NOT_FOUND |
| 36 | +
|
| 37 | +The method does not exist / is not available. |
| 38 | +""" |
| 39 | +const METHOD_NOT_FOUND = -32700 |
| 40 | + |
| 41 | +""" |
| 42 | + INVALID_PARAMS |
| 43 | +
|
| 44 | +Invalid method parameter(s). |
| 45 | +""" |
| 46 | +const INVALID_PARAMS = -32700 |
| 47 | + |
| 48 | +""" |
| 49 | + INTERNAL_ERROR |
| 50 | +
|
| 51 | +Internal JSON-RPC error. |
| 52 | +""" |
| 53 | +const INTERNAL_ERROR = -32700 |
| 54 | + |
| 55 | +""" |
| 56 | + RPCErrorStrings |
| 57 | +
|
| 58 | +A `Base.IdDict` containing the mapping of JSON-RPC error codes to a short, descriptive string. |
| 59 | +
|
| 60 | +Use this to hook into `showerror(io::IO, ::JSONRPCError)` for display purposes. A default fallback to `"Unknown"` exists. |
| 61 | +""" |
| 62 | +const RPCErrorStrings = Base.IdDict( |
| 63 | + PARSE_ERROR => "ParseError", |
| 64 | + INVALID_REQUEST => "InvalidRequest", |
| 65 | + METHOD_NOT_FOUND => "MethodNotFound", |
| 66 | + INVALID_PARAMS => "InvalidParams", |
| 67 | + INTERNAL_ERROR => "InternalError", |
| 68 | + [ i => "ServerError" for i in -32099:-32000]..., |
| 69 | + # TODO: these should be removed - they are in the application/implementation specific range |
| 70 | + -32002 => "ServerNotInitialized", |
| 71 | + -32001 => "UnknownErrorCode", |
| 72 | + -32800 => "RequestCancelled", |
| 73 | + -32801 => "ContentModified" |
| 74 | +) |
| 75 | + |
7 | 76 | function Base.showerror(io::IO, ex::JSONRPCError) |
8 | | - error_code_as_string = if ex.code == -32700 |
9 | | - "ParseError" |
10 | | - elseif ex.code == -32600 |
11 | | - "InvalidRequest" |
12 | | - elseif ex.code == -32601 |
13 | | - "MethodNotFound" |
14 | | - elseif ex.code == -32602 |
15 | | - "InvalidParams" |
16 | | - elseif ex.code == -32603 |
17 | | - "InternalError" |
18 | | - elseif ex.code == -32099 |
19 | | - "serverErrorStart" |
20 | | - elseif ex.code == -32000 |
21 | | - "serverErrorEnd" |
22 | | - elseif ex.code == -32002 |
23 | | - "ServerNotInitialized" |
24 | | - elseif ex.code == -32001 |
25 | | - "UnknownErrorCode" |
26 | | - elseif ex.code == -32800 |
27 | | - "RequestCancelled" |
28 | | - elseif ex.code == -32801 |
29 | | - "ContentModified" |
30 | | - else |
31 | | - "Unkonwn" |
32 | | - end |
| 77 | + error_code_as_string = get(RPCErrorStrings, ex.code, "Unknown") |
33 | 78 |
|
34 | 79 | print(io, error_code_as_string) |
35 | 80 | print(io, ": ") |
|
0 commit comments