Bird
0
0

Identify the error in this REST API code snippet that attempts to return a 409 Conflict status: def update_resource(data): if resource_exists(data['id']): return {"error": "Conflict"}, "409" else: save(data) return {"message": "Saved"}, 201

medium📝 Debug Q6 of 15
Rest API - HTTP Status Codes
Identify the error in this REST API code snippet that attempts to return a 409 Conflict status: def update_resource(data): if resource_exists(data['id']): return {"error": "Conflict"}, "409" else: save(data) return {"message": "Saved"}, 201
AThe status code should be an integer, not a string.
BThe error message is incorrect for a conflict.
CThe function should return 404 instead of 409.
DThe save function is missing a return statement.
Step-by-Step Solution
Solution:
  1. Step 1: Check the status code data type

    The status code must be an integer, but the code returns it as a string "409".
  2. Step 2: Confirm correct status code usage

    Returning a string instead of an integer will cause an error or unexpected behavior.
  3. Final Answer:

    The status code should be an integer, not a string. -> Option A
  4. Quick Check:

    Status code must be integer, not string [OK]
Quick Trick: Always return status codes as integers, not strings [OK]
Common Mistakes:
  • Returning status code as string
  • Using wrong error message
  • Confusing 409 with 404

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes