Translate API Error Codes

Medium ⏱ 12 min 64% acceptance ★★★★★ 4.9
Write check_response(code) that does nothing for code 200, raises PermissionError for 403, FileNotFoundError for 404, and RuntimeError(f'unexpected {code}') for anything else — driven by a dict mapping codes to exception classes, not an if/elif ladder for the known codes.

Examples

Example 1
Input
check_response(404)
Output
raises FileNotFoundError
Explanation

The dict maps 404 to that class.

Constraints

  • Use a dict for 403/404.
  • 200 returns None silently.

Topics

Exception Handlingraising by lookup

Companies

StripeRazorpayPayPal

Hints

Hint 1

Store the classes themselves as values.

Hint 2

Instantiate at raise time: raise mapping[code]().

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.