-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat(api): use ValidationError with a field speficied when possible #13541
Conversation
|
||
try: | ||
group = Group.objects.get(pk=int(request.data["group_id"])) | ||
except (Group.DoesNotExist, ValueError) as error: | ||
raise ValidationError(str(error)) from error | ||
raise ValidationError({"group_id": str(error)}) from error |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
|
||
try: | ||
role = Role.objects.get(pk=int(request.data["role_id"])) | ||
except (Role.DoesNotExist, ValueError) as error: | ||
raise ValidationError(str(error)) from error | ||
raise ValidationError({"role_id": str(error)}) from error |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
|
||
try: | ||
language = Language.objects.get(code=request.data["language_code"]) | ||
except (Language.DoesNotExist, ValueError) as error: | ||
raise ValidationError(str(error)) from error | ||
raise ValidationError({"language_code": str(error)}) from error |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
|
||
try: | ||
project = Project.objects.get( | ||
pk=int(request.data["project_id"]), | ||
) | ||
except (Project.DoesNotExist, ValueError) as error: | ||
raise ValidationError(str(error)) from error | ||
raise ValidationError({"project_id": str(error)}) from error |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
|
||
try: | ||
component_list = ComponentList.objects.get( | ||
pk=int(request.data["component_list_id"]), | ||
) | ||
except (ComponentList.DoesNotExist, ValueError) as error: | ||
raise ValidationError(str(error)) from error | ||
raise ValidationError({"component_list_id": str(error)}) from error |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
|
||
try: | ||
component = Component.objects.filter_access(request.user).get( | ||
pk=int(request.data["component_id"]) | ||
) | ||
except (Component.DoesNotExist, ValueError) as error: | ||
raise ValidationError(str(error)) from error | ||
raise ValidationError({"component_id": str(error)}) from error |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
@@ -1679,7 +1673,7 @@ | |||
parse_query(query_string) | |||
except Exception as error: | |||
msg = f"Could not parse query string: {error}" | |||
raise ValidationError(msg) from error | |||
raise ValidationError({"q": msg}) from error |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
@@ -1821,7 +1815,7 @@ | |||
parse_query(query_string) | |||
except Exception as error: | |||
msg = f"Could not parse query string: {error}" | |||
raise ValidationError(msg) from error | |||
raise ValidationError({"q": msg}) from error |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
ede4cdc
to
f0fb309
Compare
- include field when it is known - avoid building 400 responses manually
This is companion to WeblateOrg#13541 to make API error response more consistent. We now rely on drf-standardized-erros to do the processing. It also has drf-spectacular integration, so the error states are now documented in OpenAPI.
|
||
service, configuration, errors = validate_service_configuration( | ||
service_name, request.data.get("configuration", "{}") | ||
) | ||
|
||
if service is None or errors: | ||
return Response({"errors": errors}, status=HTTP_400_BAD_REQUEST) | ||
raise ValidationError({"configuration": errors}) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
@@ -1199,7 +1193,7 @@ | |||
) | |||
|
|||
if service is None or errors: | |||
return Response({"errors": errors}, status=HTTP_400_BAD_REQUEST) | |||
raise ValidationError({"configuration": errors}) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
This is companion to WeblateOrg#13541 to make API error response more consistent. We now rely on drf-standardized-erros to do the processing. It also has drf-spectacular integration, so the error states are now documented in OpenAPI.
This is companion to WeblateOrg#13541 to make API error response more consistent. We now rely on drf-standardized-erros to do the processing. It also has drf-spectacular integration, so the error states are now documented in OpenAPI.
This is companion to WeblateOrg#13541 to make API error response more consistent. We now rely on drf-standardized-erros to do the processing. It also has drf-spectacular integration, so the error states are now documented in OpenAPI.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13541 +/- ##
=======================================
Coverage 90.95% 90.95%
=======================================
Files 604 604
Lines 62823 62823
Branches 6488 6488
=======================================
Hits 57140 57140
Misses 3999 3999
Partials 1684 1684
|
This is companion to WeblateOrg#13541 to make API error response more consistent. We now rely on drf-standardized-erros to do the processing. It also has drf-spectacular integration, so the error states are now documented in OpenAPI.
This is companion to WeblateOrg#13541 to make API error response more consistent. We now rely on drf-standardized-erros to do the processing. It also has drf-spectacular integration, so the error states are now documented in OpenAPI.
This is companion to WeblateOrg#13541 to make API error response more consistent. We now rely on drf-standardized-erros to do the processing. It also has drf-spectacular integration, so the error states are now documented in OpenAPI.
Proposed changes
Checklist
Other information