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

Hide validation errors in prodaction env #48

Closed
fojetin opened this issue Dec 7, 2020 · 2 comments
Closed

Hide validation errors in prodaction env #48

fojetin opened this issue Dec 7, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@fojetin
Copy link
Contributor

fojetin commented Dec 7, 2020

Hi! I need to hide {"detail": errors} on prod env. It's error after _get_values(request, kw)

I think, we should add some param to NinjaAPI, like hide_errors, to hide detail in error.
@vitalik do you approve this solution?

@fojetin fojetin changed the title Hide docs in prodaction env Hide validation errors in prodaction env Dec 8, 2020
@vitalik
Copy link
Owner

vitalik commented Dec 8, 2020

this will be possible with custom response classes (along with #6)

@vitalik vitalik added the enhancement New feature or request label Dec 8, 2020
@vitalik
Copy link
Owner

vitalik commented Jan 18, 2021

@fojetin

This is now possible with response renderers

from ninja.renderers import JSONRenderer

class MyRenderer(JSONRenderer):

    def render(self, request, data, *, response_status):
        if not settings.DEBUG and response_status == 422:
                data = {"error": True}
        return super().render(request, data, response_status=response_status)


api = NinjaAPI(renderer=MyRenderer())

@vitalik vitalik closed this as completed Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants