cloudinary_java icon indicating copy to clipboard operation
cloudinary_java copied to clipboard

Upload API throws RuntimeException

Open JulienArzul opened this issue 9 years ago • 2 comments

Hello,

You should provide an easy way to handle upload errors in your SDK.

The method signature suggests that you will be throwing an IOException but looking at the source code, we can see that you're actually throwing RuntimeException in several cases ! These cases should be handled differently in the SDK so that the caller can identify them : they are definitely not a reason to throw a RuntimeException.

At the minimum, you should throw a IOException as specified by the upload signature. Alternatively, you could think about a nicer error handling system, either with a custom Exception or with a specific Map returned (whose values should be documented !).

JulienArzul avatar May 02 '16 14:05 JulienArzul

Hi @JulienArzul, You may have a point here however we cannot change the exception to IOException without changing the method signature and thus breaking backward compatibility. We'll revisit this issue on the next major version release.

tocker avatar May 18 '16 07:05 tocker

+1

You may have a point here however we cannot change the exception to IOException without changing the method signature and thus breaking backward compatibility.

Actually you can change it without changing the signature -- the method already declares throws IOException. It just doesn't.

However, I'd note @JulienArzul's other comment: better to use a custom exception type that allows extracting the status code and a Map that contains the body of the response, or some structured type with the same values.

rocketraman avatar Jun 02 '16 20:06 rocketraman