Index: pkg/json_rpc_2/lib/error_code.dart |
diff --git a/pkg/json_rpc_2/lib/error_code.dart b/pkg/json_rpc_2/lib/error_code.dart |
index 96cb909a314c1b43460526939be225fef554c672..14b77f2e09b2feb83dac3334ad69a574cd8ed034 100644 |
--- a/pkg/json_rpc_2/lib/error_code.dart |
+++ b/pkg/json_rpc_2/lib/error_code.dart |
@@ -34,3 +34,18 @@ const INTERNAL_ERROR = -32603; |
/// The spec reserves the range from -32000 to -32099 for implementation-defined |
/// server exceptions, but for now we only use one of those values. |
const SERVER_ERROR = -32000; |
+ |
+/// Returns a human-readable name for [errorCode] if it's one specified by the |
+/// JSON-RPC 2.0 spec. |
+/// |
+/// If [errorCode] isn't defined in the JSON-RPC 2.0 spec, returns null. |
+String name(int errorCode) { |
+ switch (errorCode) { |
+ case PARSE_ERROR: return "parse error"; |
+ case INVALID_REQUEST: return "invalid request"; |
+ case METHOD_NOT_FOUND: return "method not found"; |
+ case INVALID_PARAMS: return "invalid parameters"; |
+ case INTERNAL_ERROR: return "internal error"; |
+ default: return null; |
+ } |
+} |