api: properly encode exception type
When using `str(type(exception))` this ends up to be something like `<class 'ValueError'>` for a `ValueError` exception. Get the vanilla name of the exception type via `type(exception).__name__`. Add a test to ensure that we encode this properly.
This commit is contained in:
parent
f5d00dd043
commit
f8de164413
2 changed files with 2 additions and 1 deletions
|
|
@ -213,7 +213,7 @@ def exception(e, path="/run/osbuild/api/osbuild"):
|
|||
msg = {
|
||||
"method": "exception",
|
||||
"exception": {
|
||||
"type": str(type(e)),
|
||||
"type": type(e).__name__,
|
||||
"value": str(e),
|
||||
"traceback": str(e.__traceback__)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ class TestAPI(unittest.TestCase):
|
|||
for field in ("type", "value", "traceback"):
|
||||
self.assertIn(field, e, f"Exception needs '{field}'")
|
||||
self.assertEqual(e["value"], "osbuild test exception")
|
||||
self.assertEqual(e["type"], "ValueError")
|
||||
|
||||
def test_metadata(self):
|
||||
# Check that `api.metadata` leads to `API.metadata` being
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue