Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'exception' as extra detail field in problem responses everywhere. #986

Merged
merged 1 commit into from Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion auslib/web/admin/emergency_shutoff.py
Expand Up @@ -23,7 +23,7 @@ def shutoff_exists(product, channel):
@handleGeneralExceptions("POST")
def post(emergency_shutoff, changed_by, transaction):
if shutoff_exists(emergency_shutoff["product"], emergency_shutoff["channel"]):
return problem(400, "Bad Request", "Invalid Emergency shutoff data", ext={"data": "Emergency shutoff for product/channel already exists."})
return problem(400, "Bad Request", "Invalid Emergency shutoff data", ext={"exception": "Emergency shutoff for product/channel already exists."})
inserted_shutoff = dbo.emergencyShutoffs.insert(
changed_by=changed_by, transaction=transaction, product=emergency_shutoff["product"], channel=emergency_shutoff["channel"]
)
Expand Down
28 changes: 14 additions & 14 deletions auslib/web/admin/views/releases.py
Expand Up @@ -145,11 +145,11 @@ def changeRelease(release, changed_by, transaction, existsCallback, commitCallba
except BlobValidationError as e:
msg = "Couldn't create release: %s" % e
log.warning("Bad input: %s", rel)
return problem(400, "Bad Request", msg, ext={"data": e.errors})
return problem(400, "Bad Request", msg, ext={"exception": e.errors})
except ValueError as e:
msg = "Couldn't create release: %s" % e
log.warning("Bad input: %s", rel)
return problem(400, "Bad Request", msg, ext={"data": e.args})
return problem(400, "Bad Request", msg, ext={"exception": e.args})
old_data_version = 1

extraArgs = {}
Expand All @@ -160,15 +160,15 @@ def changeRelease(release, changed_by, transaction, existsCallback, commitCallba
except BlobValidationError as e:
msg = "Couldn't update release: %s" % e
log.warning("Bad input: %s", rel)
return problem(400, "Bad Request", msg, ext={"data": e.errors})
return problem(400, "Bad Request", msg, ext={"exception": e.errors})
except ReadOnlyError as e:
msg = "Couldn't update release: %s" % e
log.warning("Bad input: %s", rel)
return problem(403, "Forbidden", msg, ext={"data": e.args})
return problem(403, "Forbidden", msg, ext={"exception": e.args})
except (ValueError, OutdatedDataError) as e:
msg = "Couldn't update release: %s" % e
log.warning("Bad input: %s", rel)
return problem(400, "Bad Request", msg, ext={"data": e.args})
return problem(400, "Bad Request", msg, ext={"exception": e.args})

new_data_version = dbo.releases.getReleases(name=release, transaction=transaction)[0]["data_version"]
if new:
Expand Down Expand Up @@ -230,15 +230,15 @@ def _put(self, release, changed_by, transaction):
except BlobValidationError as e:
msg = "Couldn't update release: %s" % e
self.log.warning("Bad input: %s", msg)
return problem(400, "Bad Request", "Couldn't update release", ext={"data": e.errors})
return problem(400, "Bad Request", "Couldn't update release", ext={"exception": e.errors})
except ReadOnlyError as e:
msg = "Couldn't update release: %s" % e
self.log.warning("Bad input: %s", msg)
return problem(403, "Forbidden", "Couldn't update release. Release is marked read only", ext={"data": e.args})
return problem(403, "Forbidden", "Couldn't update release. Release is marked read only", ext={"exception": e.args})
except ValueError as e:
msg = "Couldn't update release: %s" % e
self.log.warning("Bad input: %s", msg)
return problem(400, "Bad Request", "Couldn't update release", ext={"data": e.args})
return problem(400, "Bad Request", "Couldn't update release", ext={"exception": e.args})
# the data_version might jump by more than 1 if outdated blobs are
# merged
data_version = dbo.releases.getReleases(name=release, transaction=transaction)[0]["data_version"]
Expand All @@ -252,11 +252,11 @@ def _put(self, release, changed_by, transaction):
except BlobValidationError as e:
msg = "Couldn't update release: %s" % e
self.log.warning("Bad input: %s", msg)
return problem(400, "Bad Request", "Couldn't update release", ext={"data": e.errors})
return problem(400, "Bad Request", "Couldn't update release", ext={"exception": e.errors})
except ValueError as e:
msg = "Couldn't update release: %s" % e
self.log.warning("Bad input: %s", msg)
return problem(400, "Bad Request", "Couldn't update release", ext={"data": e.args})
return problem(400, "Bad Request", "Couldn't update release", ext={"exception": e.args})
return Response(status=201)

@requirelogin
Expand Down Expand Up @@ -290,7 +290,7 @@ def _delete(self, release, changed_by, transaction):
except ReadOnlyError as e:
msg = "Couldn't delete release: %s" % e
self.log.warning("Bad input: %s", msg)
return problem(403, "Forbidden", "Couldn't delete %s. Release is marked read only" % release["name"], ext={"data": e.args})
return problem(403, "Forbidden", "Couldn't delete %s. Release is marked read only" % release["name"], ext={"exception": e.args})

return Response(status=200)

Expand Down Expand Up @@ -347,7 +347,7 @@ def _post(self, changed_by, transaction):
400,
"Bad Request",
"Release: %s already exists" % connexion.request.get_json().get("name"),
ext={"data": "Database already contains the release"},
ext={"exception": "Database already contains the release"},
)
try:
blob = createBlob(connexion.request.get_json().get("blob"))
Expand All @@ -361,11 +361,11 @@ def _post(self, changed_by, transaction):
except BlobValidationError as e:
msg = "Couldn't create release: %s" % e
self.log.warning("Bad input: %s", msg)
return problem(400, "Bad Request", "Couldn't create release", ext={"data": e.errors})
return problem(400, "Bad Request", "Couldn't create release", ext={"exception": e.errors})
except ValueError as e:
msg = "Couldn't create release: %s" % e
self.log.warning("Bad input: %s", msg)
return problem(400, "Bad Request", "Couldn't create release", ext={"data": e.args})
return problem(400, "Bad Request", "Couldn't create release", ext={"exception": e.args})

release = dbo.releases.getReleases(name=name, transaction=transaction, limit=1)[0]
return Response(status=201, response=json.dumps(dict(new_data_version=release["data_version"])))
Expand Down