{"record":{"id":"2bffd453c7bc2ff9","repo":"tiangolo/fastapi","slug":"nope-i-don-t-like-3-2bffd4","errorCode":null,"errorMessage":"Nope! I don't like 3.","messagePattern":"Nope! I don't like 3\\.","errorType":"http","errorClass":"HTTPException","httpStatus":418,"severity":"warning","filePath":"docs_src/handling_errors/tutorial006_py310.py","lineNumber":27,"sourceCode":"app = FastAPI()\n\n\n@app.exception_handler(StarletteHTTPException)\nasync def custom_http_exception_handler(request, exc):\n    print(f\"OMG! An HTTP error!: {repr(exc)}\")\n    return await http_exception_handler(request, exc)\n\n\n@app.exception_handler(RequestValidationError)\nasync def validation_exception_handler(request, exc):\n    print(f\"OMG! The client sent invalid data!: {exc}\")\n    return await request_validation_exception_handler(request, exc)\n\n\n@app.get(\"/items/{item_id}\")\nasync def read_item(item_id: int):\n    if item_id == 3:\n        raise HTTPException(status_code=418, detail=\"Nope! I don't like 3.\")\n    return {\"item_id\": item_id}\n","sourceCodeStart":9,"sourceCodeEnd":29,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/docs_src/handling_errors/tutorial006_py310.py#L9-L29","documentation":"Same HTTPException(418) as error 35 but in tutorial006, which overrides the default handlers by delegating to FastAPI's built-in http_exception_handler and request_validation_exception_handler after logging. The 418 fires for item_id == 3 and is processed by the custom handler that prints 'OMG! An HTTP error!' before returning the standard JSON error.","triggerScenarios":"GET /items/3. Other integers return 200; non-integers return 400 via the logging validation handler.","commonSituations":"Centralized error logging via exception handlers. Developers see 418 for the sentinel value 3 and notice server-side log output for every HTTP/validation error.","solutions":["Request GET /items/{n} with n != 3.","Use a conventional status code if 418 is not intentional.","Keep the delegation to built-in handlers so response shape stays consistent."],"exampleFix":"// before\nif item_id == 3:\n    raise HTTPException(status_code=418, detail=\"Nope! I don't like 3.\")\n// after\nif item_id == 3:\n    raise HTTPException(status_code=400, detail=\"Value 3 is not allowed\")","handlingStrategy":"validation","validationCode":"if item_id == 3:\n    print('will return 418 (logged server-side)')","typeGuard":"def is_allowed_item(item_id: int) -> bool:\n    return item_id != 3","tryCatchPattern":"resp = requests.get(f'http://localhost:8000/items/{item_id}')\nif resp.status_code == 418:\n    print('rejected (server logged OMG)')","preventionTips":["Avoid the sentinel value 3.","Watch server logs; every HTTP/validation error is printed.","Use conventional status codes in production."],"tags":["fastapi","http-418","exception-handler","logging"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}