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

Fix return overrides to override error bodies #2815

Merged
merged 2 commits into from
Jan 21, 2020

Conversation

buger
Copy link
Member

@buger buger commented Jan 20, 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.

Example python middleware:

from tyk.decorators import *
from gateway import TykGateway as tyk

@Hook
def MyRequestHook(request, response, session, metadata, spec):
	request.object.return_overrides.headers['X-Foo'] = 'Bar'
	request.object.return_overrides.response_code = 501
        request.object.return_overrides.response_body = "custom error"
        request.object.return_overrides.override_error = True

	return request, session

#2693

Previous PR 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`, becauee it makes way more sense.
Old field still can be set for backward compatibility.

Fix #2731
@buger buger merged commit 3fd2820 into master Jan 21, 2020
@buger buger deleted the fix/2693-fix-return-overrides branch January 21, 2020 06:36
@buger
Copy link
Member Author

buger commented Jan 21, 2020

/release to release-2.9

@tykbot
Copy link

tykbot bot commented Jan 21, 2020

Working on it! Note that it can take a few minutes.

@tykbot
Copy link

tykbot bot commented Jan 21, 2020

@buger Seems like there is conflict and it require manual merge.

buger added a commit that referenced this pull request 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 pushed a commit that referenced this pull request Jan 27, 2020
matiasinsaurralde added a commit to matiasinsaurralde/tyk that referenced this pull request Apr 15, 2020
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.

1 participant