Dorthu / openapi3

A Python3 OpenAPI 3 Spec Parser
BSD 3-Clause "New" or "Revised" License
118 stars 47 forks source link

bug: Use custom error class for undeclared responses #81

Closed Dorthu closed 2 years ago

Dorthu commented 2 years ago

Closes #80

When this library is used as a client and the server returns a response that was not declared in the operation's responses, an exception is raised. Right now, this is a RuntimeError with a message explaining what code was returned, and that it was undocumented. This is not useful when using the client against an API whose documentation you do not control, and that is missing exhaustive documentation for responses (generally error responses fall into this category).

This change adds a new error type, openapi3.UnexpectedResponseError, and raises that instead of RuntimeError. In addition to the message, this error includes the full response that was returned, the operation that made the call, and the status code that was not expected. This new error is a subclass of RuntimeError to preserve backward compatibility.