You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think a fallback can be used, as the second argument of getReasonPhrase.
If a fallback is provided, it will be used as the return value if no matching code is found.
Otherwise, an exception will be thrown as usual.
This approach is backward compatible and covers probably the most common use case of trying to get a phrase from a code or using a specified alternative.
I was very surprised to discover that
getReasonPhrase
throws an exception when given an HTTP status code that the library does not know about.Could we add non-throwing variants of
getReasonPhrase
andgetStatusCode
that returnundefined
instead of throwing an exception?Having to catch the exception just to handle these cases gracefully is not very ergonomic.
I would be willing to open a PR for this if it would be accepted.
The text was updated successfully, but these errors were encountered: