http Response Error Checking
Hi all, I am a IBM business partner using this library for a plugin for IBM's APM platform. Thanks for the great library! I am in need of error checking and possibly retrying certain requests depending on the response code of each request. I have tried to extend RestApiClient, but I need to override logAndHandleResponse in the ServiceProxy class. But this class is private-protected. If i try to implement my own version of this class, I cannot call mask.getMask() because it is not in the same package as Mask at this point. Thanks for considering this request for enhancement.
Why not catch the exception that is thrown? ApiException contains the status code among other things. Is there something not visible via the caught exception that requires this kind of override?
Thanks for the response! The biggest problem is there can be 500+ exceptions thrown for a single environment, and raising that many exceptions is expensive. But currently that is how we are doing it. This is the response raising the ApiException:
Got 500 on https://api.softlayer.com/rest/v3.1/SoftLayer_Virtual_Guest/{ID}/MonitoringActiveAlarms.json with body: {"error":"Monitoring service is not enabled on {fqdn}","code":"SoftLayer_Exception"}
raising that many exceptions is expensive
These days, not really. the JVM is highly optimized for these kinds of use cases, and local catches are almost as performant as your virtual override might be. And we're using reflection significantly here, so clearly shaving a couple of microseconds here and there for exceptions is not worthy while you have all of these other not-the-highest-performing approaches in use for ease of development. I mean if you want that high performing, why not use a highly optimized HTTP library and handle the response without serialization and many many other micro-optimizations you could do instead of use this library?
Granted, exceptions shouldn't be used as control flow, but this is an actual exception and worthy of an exception. A better approach would undoubtedly be to attempt to query for the exceptional circumstance if possible (in this case, unsure, but can you determine whether monitoring service is enabled before obtaining the alarms?).
Either way, my personal opinion is that catching the exception is the reasonable pattern if you need to act on an error. But I am not the maintainer of this library so I will defer if they want to provide some other way for you to get the error.
Thanks for the input. Unfortunately, we cannot save state; so, every minute the only way to know if this exception will occur, is to send an additional API call for each device. Thanks again for your time.