async def starlette_exception():
    raise HTTPException(
        status_code=400,
        detail="required",
        fields=[{"field": "value"}],
        error_code=400
    )
Esempio n. 2
0
def test_http_exception():
    detail = "Random HTTP error happened."
    status_code = status.HTTP_400_BAD_REQUEST
    error_code = 999
    with pytest.raises(HTTPException) as excinfo:
        raise HTTPException(
            status_code=status_code,
            error_code=error_code,
            detail=detail,
            fields=[{
                "field": "because of this."
            }],
        )

    exc = excinfo.value
    assert exc.error_code == error_code
    assert exc.detail == detail
    assert exc.status_code == status_code
    assert exc.fields == [{"field": "because of this."}]
Esempio n. 3
0
 def __init__(self, request: Request):
     if not self.has_required_permissions(request):
         raise HTTPException(status_code=self.status_code,
                             detail=self.error_msg,
                             error_code=self.error_code)