Conditions | 4 |
Total Lines | 16 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | """Custom validator for the Annif API.""" |
||
24 | def _validate(self, body: Any) -> dict | None: |
||
25 | try: |
||
26 | return self._validator.validate(body) |
||
27 | except ValidationError as exception: |
||
28 | if exception.validator == "maxItems" and list(exception.schema_path) == [ |
||
29 | "properties", |
||
30 | "documents", |
||
31 | "maxItems", |
||
32 | ]: |
||
33 | exception.message = "too many items" |
||
34 | error_path_msg = format_error_with_path(exception=exception) |
||
35 | logger.error( |
||
36 | f"Validation error: {exception.message}{error_path_msg}", |
||
37 | extra={"validator": "body"}, |
||
38 | ) |
||
39 | raise BadRequestProblem(detail=f"{exception.message}{error_path_msg}") |
||
40 |