All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.svix.exceptions.ApiException Maven / Gradle / Ivy

There is a newer version: 1.36.0
Show newest version
package com.svix.exceptions;

import java.util.Map;
import java.util.List;
import com.google.gson.Gson;

class APIError {
    private String code;
    private String detail;

    public String getCode() {
        return this.code;
    }

    public String getDetail() {
        return this.detail;
    }
}

public class ApiException extends com.svix.internal.ApiException {

    private String message;

    public ApiException(final String message, final Throwable throwable, final int code, final Map> responseHeaders, final String responseBody) {
        super(message, throwable, code, responseHeaders, responseBody);

        if ((message == null || message.isEmpty()) && responseBody != null) {
            try {
                Gson gson = new Gson();
                APIError error = gson.fromJson(responseBody, APIError.class);
                this.message = String.format("%s (%s)", error.getDetail(), error.getCode());
            } catch (Exception e) {
                this.message = responseBody;
            }
        }
    }

    public String getMessage() {
        String msg = super.getMessage();
        if (msg != null && !msg.isEmpty()) {
            return msg;
        }
        return this.message;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy