EUDAT-B2STAGE / http-api

RESTful HTTP-API for the B2STAGE service inside the EUDAT project
https://eudat-b2stage.github.io/http-api/
MIT License
7 stars 7 forks source link

Internal Server Error because part of response cannot be parsed to json #123

Closed merretbuurman closed 5 years ago

merretbuurman commented 6 years ago

If Rancher returns errors, they are added to the response. The problem is that they are not dictionaries, but some Rancher data type, which cannot be jsonified ([ERROR restapi.rest.response:136] Cannot jsonify rv:), so the whole thing crashes and return an undescribed Internal Server Error (500) to the client:

backend_1 | 2018-08-29T14:11:16.791544981Z 2018-08-29 14:11:16,734 [ERROR restapi.rest.response:136] Cannot jsonify rv: backend_1 | 2018-08-29T14:11:16.791610968Z { backend_1 | 2018-08-29T14:11:16.791632094Z 'Meta': { backend_1 | 2018-08-29T14:11:16.791649268Z 'data_type': '<class 'dict'>', backend_1 | 2018-08-29T14:11:16.791666878Z 'elements': 3, backend_1 | 2018-08-29T14:11:16.791683225Z 'errors': 0, backend_1 | 2018-08-29T14:11:16.791699708Z 'status': 200, backend_1 | 2018-08-29T14:11:16.791729326Z }, backend_1 | 2018-08-29T14:11:16.791746512Z 'Response': { backend_1 | 2018-08-29T14:11:16.791762935Z 'data': { backend_1 | 2018-08-29T14:11:16.791779392Z 'batch_id': 'log42', backend_1 | 2018-08-29T14:11:16.791795679Z 'errors': { backend_1 | 2018-08-29T14:11:16.791812539Z 'error': {'status': 422, 'code': 'NotUnique', 'message': None, 'detail': None, 'fieldName': 'name', 'baseType': 'error'} backend_1 | 2018-08-29T14:11:16.791830052Z }, backend_1 | 2018-08-29T14:11:16.791846462Z 'status': 'existing', backend_1 | 2018-08-29T14:11:16.791862949Z }, backend_1 | 2018-08-29T14:11:16.791879419Z 'errors': None, backend_1 | 2018-08-29T14:11:16.791895842Z }, backend_1 | 2018-08-29T14:11:16.791911786Z }

(Reproduction: This can happen if the same file is uploaded twice, so rancher attempts to create a container of the same and and fails with code "NotUnique".)

Which leads to:

backend_1 | 2018-08-29T14:11:16.828213484Z 2018-08-29 14:11:16,769 [ERROR flask.app:1761] Exception on /api/ingestion/log42/add/log42 [PUT] backend_1 | 2018-08-29T14:11:16.828247694Z Traceback (most recent call last): backend_1 | 2018-08-29T14:11:16.828265311Z File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1974, in make_response backend_1 | 2018-08-29T14:11:16.828282641Z rv = self.response_class.force_type(rv, request.environ) backend_1 | 2018-08-29T14:11:16.828298820Z File "/usr/local/lib/python3.6/dist-packages/restapi/rest/response.py", line 139, in force_type backend_1 | 2018-08-29T14:11:16.828315594Z return super(InternalResponse, cls).force_type(rv, environ) backend_1 | 2018-08-29T14:11:16.828331820Z File "/usr/local/lib/python3.6/dist-packages/werkzeug/wrappers.py", line 921, in force_type backend_1 | 2018-08-29T14:11:16.828348571Z response = BaseResponse(_run_wsgi_app(response, environ)) backend_1 | 2018-08-29T14:11:16.836347014Z File "/usr/local/lib/python3.6/dist-packages/werkzeug/wrappers.py", line 59, in _run_wsgi_app backend_1 | 2018-08-29T14:11:16.836415657Z return _run_wsgi_app(args) backend_1 | 2018-08-29T14:11:16.836493912Z File "/usr/local/lib/python3.6/dist-packages/werkzeug/test.py", line 923, in run_wsgi_app backend_1 | 2018-08-29T14:11:16.836512448Z app_rv = app(environ, start_response) backend_1 | 2018-08-29T14:11:16.836528978Z TypeError: 'dict' object is not callable backend_1 | 2018-08-29T14:11:16.836545225Z backend_1 | 2018-08-29T14:11:16.836560868Z During handling of the above exception, another exception occurred: backend_1 | 2018-08-29T14:11:16.836577065Z backend_1 | 2018-08-29T14:11:16.836592205Z Traceback (most recent call last): backend_1 | 2018-08-29T14:11:16.836608005Z File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2292, in wsgi_app backend_1 | 2018-08-29T14:11:16.836624158Z response = self.full_dispatch_request() backend_1 | 2018-08-29T14:11:16.836639518Z File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1816, in full_dispatch_request backend_1 | 2018-08-29T14:11:16.836655728Z return self.finalize_request(rv) backend_1 | 2018-08-29T14:11:16.836671178Z File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1831, in finalize_request backend_1 | 2018-08-29T14:11:16.836687465Z response = self.make_response(rv) backend_1 | 2018-08-29T14:11:16.836703031Z File "/usr/local/lib/python3.6/dist-packages/restapi/server.py", line 68, in make_response backend_1 | 2018-08-29T14:11:16.836719294Z return super().make_response(response) backend_1 | 2018-08-29T14:11:16.836735061Z File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1982, in make_response backend_1 | 2018-08-29T14:11:16.836751031Z reraise(TypeError, new_error, sys.exc_info()[2]) backend_1 | 2018-08-29T14:11:16.836766918Z File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 34, in reraise backend_1 | 2018-08-29T14:11:16.836783025Z raise value.with_traceback(tb) backend_1 | 2018-08-29T14:11:16.836798681Z File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1974, in make_response backend_1 | 2018-08-29T14:11:16.836814868Z rv = self.response_class.force_type(rv, request.environ) backend_1 | 2018-08-29T14:11:16.836833771Z File "/usr/local/lib/python3.6/dist-packages/restapi/rest/response.py", line 139, in force_type backend_1 | 2018-08-29T14:11:16.836851394Z return super(InternalResponse, cls).force_type(rv, environ) backend_1 | 2018-08-29T14:11:16.836867121Z File "/usr/local/lib/python3.6/dist-packages/werkzeug/wrappers.py", line 921, in force_type backend_1 | 2018-08-29T14:11:16.836883234Z response = BaseResponse(_run_wsgi_app(response, environ)) backend_1 | 2018-08-29T14:11:16.836898974Z File "/usr/local/lib/python3.6/dist-packages/werkzeug/wrappers.py", line 59, in _run_wsgi_app backend_1 | 2018-08-29T14:11:16.836920994Z return _run_wsgi_app(args) backend_1 | 2018-08-29T14:11:16.836937127Z File "/usr/local/lib/python3.6/dist-packages/werkzeug/test.py", line 923, in run_wsgi_app backend_1 | 2018-08-29T14:11:16.836953561Z app_rv = app(environ, start_response) backend_1 | 2018-08-29T14:11:16.836969154Z TypeError: 'dict' object is not callable backend_1 | 2018-08-29T14:11:16.836997087Z The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a dict. backend_1 | 2018-08-29T14:11:16.837015294Z [pid: 59|app: 0|req: 1/3] 172.30.0.3 () {48 vars in 924 bytes} [Wed Aug 29 14:11:15 2018] PUT /api/ingestion/log42/add/log42 => generated 153 bytes in 1789 msecs (HTTP/1.0 500) 2 headers in 91 bytes (1 switches on core 0)

mdantonio commented 6 years ago

@merretbuurman this issue and the corresponding PR are still open, due to errors in the PR... could you have a look?