-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
api.load_json(ctx, database, engine, "myjson", """{"a" : "b"}""")
fail with stacktraces like:
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
Input In [24], in <module>
----> 1 api.load_json(ctx, database, engine, "myjson", """{"a" : "b"}""")
File ~/anaconda3/envs/py310/lib/python3.9/site-packages/railib/api.py:531, in load_json(ctx, database, engine, relation, data)
528 inputs = {'data': data}
529 command = ("def config:data = data\n"
530 "def insert:%s = load_json[config]" % relation)
--> 531 return query(ctx, database, engine, command, inputs=inputs, readonly=False)
File ~/anaconda3/envs/py310/lib/python3.9/site-packages/railib/api.py:537, in query(ctx, database, engine, command, inputs, readonly)
534 def query(ctx: Context, database: str, engine: str, command: str,
535 inputs: dict = None, readonly: bool = True) -> dict:
536 tx = Transaction(database, engine, readonly=readonly)
--> 537 return tx.run(ctx, _query_action(command, inputs=inputs))
File ~/anaconda3/envs/py310/lib/python3.9/site-packages/railib/api.py:322, in Transaction.run(self, ctx, *args)
320 kwargs["source_dbname"] = self.source_database
321 url = _mkurl(ctx, PATH_TRANSACTION)
--> 322 rsp = rest.post(ctx, url, data, **kwargs)
323 return json.loads(rsp)
File ~/anaconda3/envs/py310/lib/python3.9/site-packages/railib/rest.py:252, in post(ctx, url, data, headers, **kwargs)
251 def post(ctx: Context, url: str, data, headers={}, **kwargs) -> str:
--> 252 return request(ctx, "POST", url, headers=headers, data=data, **kwargs)
File ~/anaconda3/envs/py310/lib/python3.9/site-packages/railib/rest.py:235, in request(ctx, method, url, headers, data, **kwargs)
233 req = _authenticate(ctx, req)
234 _print_request(req)
--> 235 with urlopen(req) as rsp:
236 return rsp.read()
File ~/anaconda3/envs/py310/lib/python3.9/urllib/request.py:214, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
212 else:
213 opener = _opener
--> 214 return opener.open(url, data, timeout)
File ~/anaconda3/envs/py310/lib/python3.9/urllib/request.py:523, in OpenerDirector.open(self, fullurl, data, timeout)
521 for processor in self.process_response.get(protocol, []):
522 meth = getattr(processor, meth_name)
--> 523 response = meth(req, response)
525 return response
File ~/anaconda3/envs/py310/lib/python3.9/urllib/request.py:632, in HTTPErrorProcessor.http_response(self, request, response)
629 # According to RFC 2616, "2xx" code indicates that the client's
630 # request was successfully received, understood, and accepted.
631 if not (200 <= code < 300):
--> 632 response = self.parent.error(
633 'http', request, response, code, msg, hdrs)
635 return response
File ~/anaconda3/envs/py310/lib/python3.9/urllib/request.py:561, in OpenerDirector.error(self, proto, *args)
559 if http_err:
560 args = (dict, 'default', 'http_error_default') + orig_args
--> 561 return self._call_chain(*args)
File ~/anaconda3/envs/py310/lib/python3.9/urllib/request.py:494, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
492 for handler in handlers:
493 func = getattr(handler, meth_name)
--> 494 result = func(*args)
495 if result is not None:
496 return result
File ~/anaconda3/envs/py310/lib/python3.9/urllib/request.py:641, in HTTPDefaultErrorHandler.http_error_default(self, req, fp, code, msg, hdrs)
640 def http_error_default(self, req, fp, code, msg, hdrs):
--> 641 raise HTTPError(req.full_url, code, msg, hdrs, fp)
HTTPError: HTTP Error 422: Unprocessable Entity
in case of client-side (422) errors. I suspect this is true for most of the api functions. We should handle them more gracefully and with better errors.