cf-java-client
cf-java-client copied to clipboard
Exception handling on "API down for maintenance"
Documented in the case of https://github.com/promregator/promregator/issues/96#issuecomment-490585118, Promregator (a consumer of cf-java-client) encountered the situation that the CF Cloud Controller did not respond with a proper response, but only returned the ASCII string
API down for maintenance
instead of the corresponding JSON. I stumbled over https://github.com/cloudfoundry/capi-release/releases/tag/1.77.0, where the second line in the highlights suggests that this is a standard behavior of the platform (and also might have reported that error without providing the appropriate HTTP status code of 503).
Based on the logs, it seems that cf-java-client today reacts to just forward an exception of type io.netty.handler.codec.CorruptedFrameException. It is clear that the corresponding request cannot be fulfilled and some sort of error reporting/exception handling must take place in this case.
What is unclear to me is who should be in charge of handling such a kind of exception. I doubt that a consumer application should catch exceptions raised by netty due to a decoding issue. Moreover, the situation appears to be (perhaps not a desired situation, but still) a response that may happen from time to time. One may also argue whether this is covered by the contract.
What is your opinion about all this? Should the consumer of cf-java-client handle this kind of failure by catching io.netty.handler.codec.CorruptedFrameException?
We could catch the CorruptedFrameException and wrap it. I'm not sure what would be the best exception in which to wrap it. It could be corrupt for any number of reasons. We have UnknowCloudFoundryException which could possibly work but that expects a 4xx/5xx response code and it doesn't seem like that was happening (based on the CAPI release notes). For that matter, I wonder if this is still a problem since they have started returning a 503 error message. Is this still an issue that you're seeing with more recent versions of CAPI?
Another possibility, we could create a new exception, like CloudFoundryMaintenanceException or MaintenanceCloudFoundryException. If there is a CorruptedFrameException and the message body contains 41504920646f776e20666f72206d61696e74656e616e6365 (i.e. API down for maintenance) we could rethrow as this exception.
Would any of that help as a consumer of the API? Other thoughts?