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

Make ReturnOverrides more flexible when returning errors #2693

Closed
matiasinsaurralde opened this issue Nov 25, 2019 · 4 comments
Closed

Make ReturnOverrides more flexible when returning errors #2693

matiasinsaurralde opened this issue Nov 25, 2019 · 4 comments

Comments

@matiasinsaurralde
Copy link
Contributor

Is your feature request related to a problem? Please describe.

  1. Currently when using rich plugins, it's possible to override the response by using ReturnOverrides, this structure takes two parameters: HTTP status code and body.

  2. When the HTTP status code is higher than 400 and a body like "test" is used, the generated response body looks like this: {"error": "test"}.

  3. It would be more flexible if we can allow the user to fully customize this behavior in error scenarios. We could keep the current functionality by default (and for compatibility purposes) and introduce a flag like disable_json_error or a similar name.
    When this flag is set to true, with the same parameters specified in 2) we would get response body like "test".

  4. This could be useful for cases where it's required to fully customize the error output.
    When using status codes lower than 400 we don't really add any JSON wrapper, so the user already has full flexibility in this case.

Describe the solution you'd like
The easiest solution would be to add a flag to the ReturnOverrides data structure. This will help us with compatibility too.

@sedkis
Copy link
Contributor

sedkis commented Nov 26, 2019

What about also letting us choose the return Code?
like in here: #2652

@buger
Copy link
Member

buger commented Nov 26, 2019

It is already possible and part of ReturnOverrides structure

@furkansenharputlu
Copy link
Contributor

Fixed by #2731

@buger buger reopened this Jan 20, 2020
buger added a commit that referenced this issue Jan 21, 2020
The previous PR #2731 contained an error, and always forced return custom error: which brakes backward compatibility.
In this PR I added tests covering all return overrides functionality and normalized its behavior for JSVM and Python.

Additionally, it use reverse logic now, and plugin needs set `ReturnOverrides.OverrideError` (JS) or `return_overrides.override_error` (Python) to `true` in order to override the body of response.

Additionally, I renamed `response_error` field to `response_body`, because it makes way more sense.
The old field still can be set for backward compatibility.

#2693
@buger
Copy link
Member

buger commented Jan 21, 2020

I added one more fix to this, details inside this PR #2815

buger added a commit that referenced this issue Jan 21, 2020
The previous PR #2731 contained an error, and always forced return custom error: which brakes backward compatibility.
In this PR I added tests covering all return overrides functionality and normalized its behavior for JSVM and Python.

Additionally, it use reverse logic now, and plugin needs set `ReturnOverrides.OverrideError` (JS) or `return_overrides.override_error` (Python) to `true` in order to override the body of response.

Additionally, I renamed `response_error` field to `response_body`, because it makes way more sense.
The old field still can be set for backward compatibility.

#2693
@buger buger closed this as completed Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants