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

Remove 'invalid api use' prefix in result when exception occurs #49

Merged

Conversation

nikhilgupta345
Copy link

@nikhilgupta345 nikhilgupta345 commented Mar 29, 2019

Since all other exceptions raised also show the traceback, we have all of our caught exceptions routed to an APIException to avoid that. However, this forces the "invalid api use" message to be prepended to all error messages, which we would like to remove.

@toumorokoshi
Copy link
Owner

Hey Nikhil, thanks for the PR! I'm thinking through this situation a little. The intention with prefixing with that value was to allow it to be obvious from the payload, regardless of the help text. For example, here's what the response looks like today for a validationerror:

{
  "headers": {},
  "code": 400,
  "result": "invalid api use: {\"number_of_cats\": [\"Value 'foo' is not int.\"]}",
  "success": false
}

I suppose it's not too bad without it:

{
  "headers": {},
  "code": 400,
  "result": "{\"number_of_cats\": [\"Value 'foo' is not int.\"]}",
  "success": false
}

Although it is not backwards-incompatible in the sense that error messages that assume that clarification.

Just to better understand: what's the rationalle to not prefix? What type of exceptions do you raise that do not count as an exception based on user input?

@nikhilgupta345
Copy link
Author

So we have a few classes of exceptions we've defined that we want to be able to throw. Examples include FailedDependencyException (self-explanatory) and a RetryableException that indicates to our frontend that they can retry. These are all subclasses of APIException, since without being an APIException they would also have the traceback returned as part of the response body.

The end goal is to be able to throw custom error messages (without the prefix) without a traceback. If there's a way to do that without using APIException please let me know!

@toumorokoshi
Copy link
Owner

The choice to log tracebacks is framework-dependent but generally true. I hear the value of returning back an exception that is more or less "expected", or indicates some behavior on the consumer.

Ultimately I think reducing assumptions from APIException is probably better than introducing some other way of doing what you're looking for. Thanks again!

@toumorokoshi toumorokoshi merged commit 242ff66 into toumorokoshi:master Mar 30, 2019
@toumorokoshi
Copy link
Owner

Released 1.13.1. Thanks! https://pypi.org/project/transmute-core/

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.

2 participants