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

Ensure all field validators return 400 with helpful message #646

Open
mihow opened this issue Dec 4, 2024 · 3 comments
Open

Ensure all field validators return 400 with helpful message #646

mihow opened this issue Dec 4, 2024 · 3 comments

Comments

@mihow
Copy link
Collaborator

mihow commented Dec 4, 2024

@annavik discovered that the field validators for GET parameters and other user-passed values are returning 500 errors instead of 400's. Also the error message data does not specify which field has a validation issue. This is because we are using Django's form field validators instead of the Django Rest Framework validators (from its serializers). Two examples that fixe this issue were introduced in #643, and this pattern needs to be applied to other cases where we are importing from django.forms (IntegerField, DateField, etc.). In general, the solution is to always make a serializer, and then call is_valid() on the serializer, which will raise a 400 error with a detailed & structured message about each field.

Also in the case that a 500 is still returned from the backend, it is possible that the response has some error information. We frontend should be able to display that as well.

@annavik
Copy link
Member

annavik commented Dec 16, 2024

When we get to this this, let's also make sure that we show any backend errors in context (below affected field) if possible. I mean frontend side. Example:

Screenshot 2024-12-16 at 10 12 29

@annavik
Copy link
Member

annavik commented Dec 16, 2024

Also I wonder about the Swedish messages that are returned from backend. I like the idea, but until rest of the app supports translations, I think mixing languages might look a bit strange. Also my browser has English language preference, so I'm a bit surprised to get messages in Swedish, is it because of my location?

@mihow
Copy link
Collaborator Author

mihow commented Dec 16, 2024

Oh that's interesting! Those are coming from Django itself, which is translated into many languages. It must see the language in your request header.

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

No branches or pull requests

2 participants