175 By default, if the HTTP Basic authentication is not provided (a
176 header), `HTTPBasic` will automatically cancel the request and send the
177▶ client an error.
178
179 If `auto_error` is set to `False`, when the HTTP Basic authentication
· · ·
179▶ If `auto_error` is set to `False`, when the HTTP Basic authentication
180 is not available, instead of erroring out, the dependency result will
181 be `None`.
· · ·
180▶ is not available, instead of erroring out, the dependency result will
181 be `None`.
182
· · ·
282 By default, if the HTTP Bearer token is not provided (in an
283 `Authorization` header), `HTTPBearer` will automatically cancel the
284▶ request and send the client an error.
285
286 If `auto_error` is set to `False`, when the HTTP Bearer token
· · ·
286▶ If `auto_error` is set to `False`, when the HTTP Bearer token
287 is not available, instead of erroring out, the dependency result will
288 be `None`.
+ 2 more matches in this file
17class HTTPException(StarletteHTTPException):
18 """
19▶ An HTTP exception you can raise in your own code to show errors to the client.
20
21 This is for client errors, invalid authentication, invalid data, etc. Not for server
· · ·
21▶ This is for client errors, invalid authentication, invalid data, etc. Not for server
22 errors in your code.
23
· · ·
22▶ errors in your code.
23
24 Read more about it in the
· · ·
25▶ [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/).
26
27 ## Example
· · ·
52
53 Read more about it in the
54▶ [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/#use-httpexception)
55 """
56 ),
+ 6 more matches in this file
32 """
33 The WWW-Authenticate header is not standardized for API Key authentication but
34▶ the HTTP specification requires that an error of 401 "Unauthorized" must
35 include a WWW-Authenticate header.
36
· · ·
112 ),
113 ] = None,
114▶ auto_error: Annotated[
115 bool,
116 Doc(
· · ·
137 scheme_name=scheme_name,
138 description=description,
139▶ auto_error=auto_error,
140 )
141
· · ·
289 ),
290 ] = None,
291▶ auto_error: Annotated[
292 bool,
293 Doc(
· · ·
313 scheme_name=scheme_name,
314 description=description,
315▶ auto_error=auto_error,
316 )
317
64 """
65 Boolean indicating if debug tracebacks should be returned on server
66▶ errors.
67
68 Read more in the
· · ·
1003 self.exception_handlers.setdefault(HTTPException, http_exception_handler)
1004 self.exception_handlers.setdefault(
1005▶ RequestValidationError, request_validation_exception_handler
1006 )
1007
· · ·
1008 # Starlette still has incorrect type specification for the handlers
1009 self.exception_handlers.setdefault(
1010▶ WebSocketRequestValidationError,
1011 websocket_request_validation_exception_handler, # type: ignore[arg-type]
1012 ) # ty: ignore[no-matching-overload]
· · ·
1022 # inside of ExceptionMiddleware, inside of custom user middlewares
1023 debug = self.debug
1024▶ error_handler = None
1025 exception_handlers: dict[Any, ExceptionHandler] = {}
1026
· · ·
1027 for key, value in self.exception_handlers.items():
1028 if key in (500, Exception):
1029▶ error_handler = value
1030 else:
1031 exception_handlers[key] = value
+ 1 more matches in this file
228 with client.websocket_connect("/depends-validate/"):
229 pass # pragma: no cover
230▶ # the validation error does produce a close message
231 assert e.value.code == status.WS_1008_POLICY_VIOLATION
232 # and no error is leaked
· · ·
232▶ # and no error is leaked
233 assert caught == []
234
· · ·
236def test_depend_err_middleware():
237 """
238▶ Verify that it is possible to write custom WebSocket middleware to catch errors
239 """
240
· · ·
257def test_depend_err_handler():
258 """
259▶ Verify that it is possible to write custom WebSocket middleware to catch errors
260 """
261
114
115def test_broken_session_stream_raise():
116▶ # Can raise ValueError on Pydantic v2 and ExceptionGroup on Pydantic v1
117 with pytest.raises((ValueError, Exception)):
118 client.get("/broken-session-stream")
403 )
404
405▶ # Extract endpoint context for error messages
406 endpoint_ctx = (
407 _extract_endpoint_context(dependant.call)
· · ·
556 # from the generator independently, so
557 # `anyio.fail_after` never wraps the generator's
558▶ # `__anext__` directly - avoiding CancelledError that
559 # would finalize the generator and also working for sync
560 # generators running in a thread pool.
20
21def test_invalid_type_value() -> None:
22▶ """Test that Schema raises ValueError for invalid type values."""
23 with pytest.raises(ValueError, match="2 validation errors for Schema"):
24 Schema(type=True) # type: ignore[arg-type] # ty: ignore[invalid-argument-type]
19 "responses": {
20 # this is how one would imagine the openapi schema to be
21▶ # but since the key is not valid, openapi.utils.get_openapi will raise ValueError
22 "hello": {"description": "Not a valid additional response"},
23 "200": {
149 CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.deprecated-tests}}
150 PYTEST_OPTIONS: ${{ (matrix.without-httpx2 == 'true') && '-W ignore::UserWarning' || '' }}
151▶ # Do not store coverage for all possible combinations to avoid file size max errors in Smokeshow
152 - name: Store coverage files
153 if: matrix.coverage == 'coverage'