| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library json_rpc_2.exception; | 5 library json_rpc_2.exception; |
| 6 | 6 |
| 7 import '../error_code.dart' as error_code; | 7 import '../error_code.dart' as error_code; |
| 8 | 8 |
| 9 /// An exception from a JSON-RPC server that can be translated into an error | 9 /// An exception from a JSON-RPC server that can be translated into an error |
| 10 /// response. | 10 /// response. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 /// Converts this exception into a JSON-serializable object that's a valid | 46 /// Converts this exception into a JSON-serializable object that's a valid |
| 47 /// JSON-RPC 2.0 error response. | 47 /// JSON-RPC 2.0 error response. |
| 48 serialize(request) { | 48 serialize(request) { |
| 49 var modifiedData; | 49 var modifiedData; |
| 50 if (data is Map && !data.containsKey('request')) { | 50 if (data is Map && !data.containsKey('request')) { |
| 51 modifiedData = new Map.from(data); | 51 modifiedData = new Map.from(data); |
| 52 modifiedData['request'] = request; | 52 modifiedData['request'] = request; |
| 53 } else if (data == null) { | 53 } else if (data == null) { |
| 54 modifiedData = {'request': request}; | 54 modifiedData = {'request': request}; |
| 55 } else { |
| 56 modifiedData = data; |
| 55 } | 57 } |
| 56 | 58 |
| 57 var id = request is Map ? request['id'] : null; | 59 var id = request is Map ? request['id'] : null; |
| 58 if (id is! String && id is! num) id = null; | 60 if (id is! String && id is! num) id = null; |
| 59 return { | 61 return { |
| 60 'jsonrpc': '2.0', | 62 'jsonrpc': '2.0', |
| 61 'error': {'code': code, 'message': message, 'data': modifiedData}, | 63 'error': {'code': code, 'message': message, 'data': modifiedData}, |
| 62 'id': id | 64 'id': id |
| 63 }; | 65 }; |
| 64 } | 66 } |
| 65 } | 67 } |
| OLD | NEW |