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

com.stackmob.sdk.exception.StackMobHTTPResponseException Maven / Gradle / Ivy

The newest version!
/**
 * Copyright 2011 StackMob
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.stackmob.sdk.exception;

import com.stackmob.sdk.util.ListHelpers;

import java.util.List;
import java.util.Map;

/**
 * An exception generated by a failed request. It contains information about the failure.
 */
public class StackMobHTTPResponseException extends StackMobException {
    private Integer code;
    private List> headers;
    private byte[] body;

    /**
     * create a new exception with info about the error response
     * @param code the response code
     * @param headers headers from the response
     * @param body the response body
     */
    public StackMobHTTPResponseException(Integer code, List> headers, byte[] body) {
        super(String.format("call failed with HTTP response code %s, headers %s, body %s", code.toString(), ListHelpers.join(headers, ", "), new String(body)));
        this.code = code;
        this.headers = headers;
        this.body = body;
    }

    /**
     * get the response code
     * @return the code
     */
    public Integer getCode() {
        return code;
    }

    /**
     * get the response headers
     * @return the headers
     */
    public List> getHeaders() {
        return headers;
    }

    /**
     * get the response body
     * @return the body
     */
    public byte[] getBody() {
        return body;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy