def localized_validation_exception_handler(request, exc): config = next((TRANSLATIONS[locale] for locale, q in parse_accept_language( request.headers.get("Accept-Language", "*")) if locale in TRANSLATIONS), Default) return JSONResponse( status_code=HTTP_422_UNPROCESSABLE_ENTITY, content={ "detail": jsonable_encoder(list(flatten_errors(exc.raw_errors, config))) }, )
def test_errors_unknown_error_object(): with pytest.raises(RuntimeError): list(flatten_errors([object]))