cloudconvert / cloudconvert-java

Official CloudConvert Java SDK
35 stars 19 forks source link

Error management #41

Closed paolobroglio closed 2 years ago

paolobroglio commented 2 years ago

Hi, I would like to make a proposal for a better error management. As i understand correctly this class is used to wrap a response. If no IOException occurs then this object is returned.

@Builder
public class Result<T> extends AbstractResult<T> {
    @Getter
    private int status;
    @Getter
    private Map<String, String> headers;
    @Getter
    private String message; // {"message":"Unauthenticated.","code":"UNAUTHENTICATED"}
    @Getter
    @Nullable
    private T body;
}

But if 40x or 50x errors occur then the message is filled with a serialized JSON object. As a user of this SDK I would like to obtain a proper deserialized error that I can use in order to perform some business logic on that. Error code enumeration would be a great feature too! Also all the errors could be wrapped by something like CloudconvertException.

Could these be viable proposals?

josiasmontag commented 2 years ago

Done, version 1.1.0 throws CloudConvertClientException (HTTP 4xx) or CloudConvertServerException (HTTP 5xx)