|
| 1 | +"""Copyright 2019 Cisco Systems |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License. |
| 14 | +""" |
1 | 15 | """Generic response wrapper class. |
2 | 16 | All responses follow the same data return format, |
3 | 17 | so generalizing the data return structure. Formalizes |
|
7 | 21 | TODO: Simplify? |
8 | 22 | """ |
9 | 23 | import json |
| 24 | +import logging |
10 | 25 |
|
11 | 26 |
|
12 | 27 | def build_response(reqid, response_stream): |
@@ -37,7 +52,10 @@ def build_response(reqid, response_stream): |
37 | 52 | response_obj = gRPCResponse(reqid) |
38 | 53 | for response in response_stream: |
39 | 54 | response_obj.add_data(response.ReqID, response.YangData, response.Errors) |
40 | | - response_obj.finalize() |
| 55 | + try: |
| 56 | + response_obj.finalize() |
| 57 | + except json.decoder.JSONDecodeError: |
| 58 | + logging.exception('Error finalizing response JSON! Returning potentially un-finalized elements.') |
41 | 59 | return response_obj |
42 | 60 |
|
43 | 61 |
|
|
0 commit comments