package io.castle.client.model;

import io.castle.client.Castle;
import okhttp3.Response;

import java.io.IOException;

public class CastleServerErrorException extends CastleRuntimeException {

    private final int responseCode;
    private final String responseMessage;
    private String response;

    public CastleServerErrorException(Response response) {
        super(response.toString());
        
        this.responseCode = response.code();
        this.responseMessage = response.message();
        try {
            this.response = response.body().string();
        } catch (NullPointerException | IOException | IllegalStateException e) {
            Castle.logger.error("CastleServerErrorException. No response body.", e);
        }
    }

    public int getResponseCode() {
        return responseCode;
    }

    public String getResponseMessage() {
        return responseMessage;
    }

    public String getResponse() {
        return response;
    }
}

@@ -961,11 +961,214 @@
 e;%0A    %7D
+%0A%0A    @Override%0A    public String getMessage() %7B%0A        if (this.response != null) %7B%0A            return super.getMessage() + %22 body: %22 + this.response;%0A        %7D%0A        return super.getMessage();%0A    %7D
 %0A%7D%0A

add body to api exception message (#119)