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

Refactor error response #85

Merged
merged 11 commits into from Feb 20, 2019
Merged

Refactor error response #85

merged 11 commits into from Feb 20, 2019

Conversation

dougthor42
Copy link
Owner

This refactors how error responses are done in the flask routes.

Previously there was a a lot of duplicated code and it was also somewhat difficult to read. This replaces those instances with a single-line class method.

Before

http_status = 404
detail = "No data exists for metric '{}'.".format(metric)
resp = utils.Rfc7807ErrorResponse(
    type_="no-data",
    title="No data for metric",
    status=http_status,
    detail=detail,
)
logger.warning("API error: %s" % detail)
return resp.as_response(), http_status

After

return ErrorResponse.metric_has_no_data(metric)

@dougthor42 dougthor42 merged commit 55b5979 into master Feb 20, 2019
@dougthor42 dougthor42 deleted the refactor-error-response branch February 20, 2019 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant