Complete the code to import HTTPException from FastAPI.
from fastapi import [1]
You need to import HTTPException from fastapi to raise HTTP errors.
Complete the code to raise a 404 HTTPException with a detail message.
raise HTTPException(status_code=[1], detail="Item not found")
404 is the standard HTTP status code for 'Not Found'.
Fix the error in raising HTTPException with a missing status_code argument.
raise HTTPException([1]=401, detail="User not authorized")
detail instead of status_code as the first argument.The status_code argument is required to specify the HTTP error code.
Fill both blanks to raise a 403 HTTPException with a custom detail message.
raise HTTPException(status_code=[1], detail=[2])
403 means forbidden access. The detail message explains the reason.
Fill both blanks to raise a 422 HTTPException with a JSON detail explaining the error.
raise HTTPException(status_code=[1], detail=[2])
422 means unprocessable entity. The detail can be a JSON string explaining the error.
