Bird
0
0

What will be the HTTP status code returned by this REST API snippet when a user tries to access a resource without permission?

medium📝 Predict Output Q4 of 15
Rest API - Error Handling

What will be the HTTP status code returned by this REST API snippet when a user tries to access a resource without permission?

if not user.has_permission:
    return {"error": "Forbidden"}, 403
A200
B401
C404
D403
Step-by-Step Solution
Solution:
  1. Step 1: Understand the meaning of 403 status code

    403 means the server understood the request but refuses to authorize it.
  2. Step 2: Match code snippet to status code

    The snippet returns 403 explicitly when permission is missing.
  3. Final Answer:

    403 -> Option D
  4. Quick Check:

    403 = Forbidden access [OK]
Quick Trick: 403 means access forbidden despite authentication [OK]
Common Mistakes:
  • Confusing 403 with 401 Unauthorized
  • Assuming 404 means no permission
  • Using 200 for error cases

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes