kstateome/canvas-api

Dealing with 5xx responses from Canvas

Closed this issue · 1 comments

This is something that I ran into recently while developing a service for Canvas - it happens very, very rarely, but should I get back a 5xx exception, the API will throw an unchecked exception (CanvasException) all the way to the client.

For most normal cases, this should be okay; it is a truly exception scenario which is no fault of the API. However, the context in which this causes a problem is inside of a running ScheduledFuture which actively polls once ever X seconds (where X >= 10). I've noticed that ScheduledFutures don't like to have unhandled exceptions thrown in them, where the ultimate resolution is that the exception will ultimately be exposed once the Future times out. This poses a problem for Futures which aren't meant to time out, or time out after a very long period of time.

The way I'd have to resolve this today would be to catch an unchecked exception, which seems and feels incredibly wrong. I'm posting this more as a question to the maintainers than anything else: would it be appropriate to revise the checkHeaders method in SimpleRequestClient to not throw an exception, and then add a new method to deal with 5xx errors such that a downstream client wouldn't have to catch the exception?

I've created this pull request to address the issue we're observing.