Join Nostr
2024-12-10 07:29:54 UTC
in reply to

alexwlchan on Nostr: Yes, once. It was in a library that wrapped a third-party API. There was a dict that ...

Yes, once.

It was in a library that wrapped a third-party API. There was a dict that mapped API error codes to named exceptions, but if the code was unrecognised I didn’t want to show the user the KeyError.

exceptions = {
1: ForbiddenException(),
2: InvalidException(),

}

try:
raise exceptions[api_response.error_code]
except KeyError:
raise UnrecognisedErrorCode(api_response.error_code) from None