Summary
Flask returns HTML error pages by default for 404 Not Found, 405 Method Not Allowed, and unhandled 500 Internal Server Error. All other endpoints in this API return JSON. Mixing HTML error responses with JSON success responses forces clients to inspect Content-Type before parsing, and is inconsistent with the API contract.
Background
A uniform error response format is a REST best practice. Clients (including the tests and Postman users) should always receive JSON with a status and msg field regardless of the error type. This is especially relevant since the tutorial targets developers learning API design.
Affected Areas
web/app.py — no @app.errorhandler registrations present
web/tests/test_app.py — no tests for 404/405 responses
Recommended Fix
@app.errorhandler(404)
def not_found(e):
return jsonify({"status": 404, "msg": "Not found"}), 404
@app.errorhandler(405)
def method_not_allowed(e):
return jsonify({"status": 405, "msg": "Method not allowed"}), 405
@app.errorhandler(500)
def internal_error(e):
return jsonify({"status": 500, "msg": "Internal server error"}), 500
Acceptance Criteria
Complexity Estimate
S — three handler functions plus test cases.
Priority
Medium — improves API consistency and client developer experience.
Auto-identified by workspace issue-logger
Category: error handling / resilience
Complexity: S
Repository: DewaldOosthuizen/python_rest_tutorial
Summary
Flask returns HTML error pages by default for 404 Not Found, 405 Method Not Allowed, and unhandled 500 Internal Server Error. All other endpoints in this API return JSON. Mixing HTML error responses with JSON success responses forces clients to inspect
Content-Typebefore parsing, and is inconsistent with the API contract.Background
A uniform error response format is a REST best practice. Clients (including the tests and Postman users) should always receive JSON with a
statusandmsgfield regardless of the error type. This is especially relevant since the tutorial targets developers learning API design.Affected Areas
web/app.py— no@app.errorhandlerregistrations presentweb/tests/test_app.py— no tests for 404/405 responsesRecommended Fix
Acceptance Criteria
{"status": N, "msg": "..."}shapeComplexity Estimate
S — three handler functions plus test cases.
Priority
Medium — improves API consistency and client developer experience.
Auto-identified by workspace issue-logger
Category: error handling / resilience
Complexity: S
Repository: DewaldOosthuizen/python_rest_tutorial