// Path: library/src/main/java/org/mariotaku/restfu/http/HttpRequest.java
// public final class HttpRequest {
// 
//     private final String method;
//     private final String url;
//     private final MultiValueMap<String> headers;
//     private final Body body;
//     private final Object tag;
// 
//     public String getMethod() {
//         return method;
//     }
// 
//     public String getUrl() {
//         return url;
//     }
// 
//     public MultiValueMap<String> getHeaders() {
//         return headers;
//     }
// 
//     public Body getBody() {
//         return body;
//     }
// 
//     public Object getTag() {
//         return tag;
//     }
// 
//     @Override
//     public String toString() {
//         StringBuilder sb = new StringBuilder(method);
//         sb.append(' ');
//         sb.append(url);
//         if (body != null) {
//             sb.append(" (has body)");
//         }
//         return sb.toString();
//     }
// 
//     public HttpRequest(String method, String url, MultiValueMap<String> headers, Body body, Object tag) {
//         this.method = method;
//         this.url = url;
//         this.headers = headers;
//         this.body = body;
//         this.tag = tag;
//     }
// 
//     public static final class Builder {
//         private String method;
//         private String url;
//         private MultiValueMap<String> headers;
//         private Body body;
//         private Object tag;
// 
//         public Builder() {
//         }
// 
//         public Builder method(String method) {
//             this.method = method;
//             return this;
//         }
// 
//         public Builder url(String url) {
//             this.url = url;
//             return this;
//         }
// 
//         public Builder headers(MultiValueMap<String> headers) {
//             this.headers = headers;
//             return this;
//         }
// 
//         public Builder body(Body body) {
//             this.body = body;
//             return this;
//         }
// 
//         public Builder tag(Object tag) {
//             this.tag = tag;
//             return this;
//         }
// 
//         public HttpRequest build() {
//             return new HttpRequest(method, url, headers, body, tag);
//         }
//     }
// 
// 
//     public static class DefaultFactory<E extends Exception> implements Factory<E> {
// 
//         @NotNull
//         @Override
//         public HttpRequest create(Endpoint endpoint, RestRequest requestInfo,
//                 Authorization authorization, RestConverter.Factory<E> converterFactory) throws E,
//                 RestConverter.ConvertException, IOException {
//             final String url = Endpoint.constructUrl(endpoint.getUrl(), requestInfo);
//             MultiValueMap<String> headers = requestInfo.getHeaders();
//             if (headers == null) {
//                 headers = new MultiValueMap<>();
//             }
//             if (authorization != null && authorization.hasAuthorization()) {
//                 headers.add("Authorization", authorization.getHeader(endpoint, requestInfo));
//             }
//             return new HttpRequest(requestInfo.getMethod(), url, headers, requestInfo.getBody(converterFactory), null);
//         }
//     }
// 
//     /**
//      * Created by mariotaku on 15/5/25.
//      */
//     public interface Factory<E extends Exception> {
//         @NotNull
//         HttpRequest create(Endpoint endpoint, RestRequest info, Authorization authorization,
//                 RestConverter.Factory<E> converterFactory) throws E, RestConverter.ConvertException, IOException;
//     }
// }
// 
// Path: library/src/main/java/org/mariotaku/restfu/http/HttpResponse.java
// public abstract class HttpResponse implements Closeable {
//     public abstract int getStatus();
// 
//     public abstract MultiValueMap<String> getHeaders();
// 
//     public abstract Body getBody();
// 
//     public String getHeader(String name) {
//         if (name == null) throw new NullPointerException();
//         return getHeaders().getFirst(name);
//     }
// 
//     public List<String> getHeaders(String name) {
//         if (name == null) throw new NullPointerException();
//         return getHeaders().get(name);
//     }
// 
//     /**
//      * Returns true if the code is in [200..300), which means the request was
//      * successfully received, understood, and accepted.
//      *
//      * @return True if HTTP response is successful response
//      */
//     public boolean isSuccessful() {
//         final int status = getStatus();
//         return status >= 200 && status < 300;
//     }
// 
//     @Override
//     public String toString() {
//         return "HTTP " + getStatus();
//     }
// }


import org.mariotaku.restfu.http.HttpRequest;
import org.mariotaku.restfu.http.HttpResponse;
/*
 * Copyright (c) 2015 mariotaku
 *
 * 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 org.mariotaku.restfu.exception;


/**
 * Created by mariotaku on 15/2/7.
 */
public class RestException extends RuntimeException {

    private HttpRequest request;
    private HttpResponse response;

    public RestException(String message, Throwable cause) {
        super(message, cause);
    }

    public RestException(String message) {
        super(message);
    }

    public RestException() {
    }

    public RestException(Throwable cause) {
        super(cause);
    }

    @Override
    public String toString() {
        return "RestException{" +
                "response=" + response +
                "} " + super.toString();
    }

    public HttpRequest getRequest() {
        return request;
    }

// Path: library/src/main/java/org/mariotaku/restfu/http/HttpRequest.java
// public final class HttpRequest {
// 
//     private final String method;
//     private final String url;
//     private final MultiValueMap<String> headers;
//     private final Body body;
//     private final Object tag;
// 
//     public String getMethod() {
//         return method;
//     }
// 
//     public String getUrl() {
//         return url;
//     }
// 
//     public MultiValueMap<String> getHeaders() {
//         return headers;
//     }
// 
//     public Body getBody() {
//         return body;
//     }
// 
//     public Object getTag() {
//         return tag;
//     }
// 
//     @Override
//     public String toString() {
//         StringBuilder sb = new StringBuilder(method);
//         sb.append(' ');
//         sb.append(url);
//         if (body != null) {
//             sb.append(" (has body)");
//         }
//         return sb.toString();
//     }
// 
//     public HttpRequest(String method, String url, MultiValueMap<String> headers, Body body, Object tag) {
//         this.method = method;
//         this.url = url;
//         this.headers = headers;
//         this.body = body;
//         this.tag = tag;
//     }
// 
//     public static final class Builder {
//         private String method;
//         private String url;
//         private MultiValueMap<String> headers;
//         private Body body;
//         private Object tag;
// 
//         public Builder() {
//         }
// 
//         public Builder method(String method) {
//             this.method = method;
//             return this;
//         }
// 
//         public Builder url(String url) {
//             this.url = url;
//             return this;
//         }
// 
//         public Builder headers(MultiValueMap<String> headers) {
//             this.headers = headers;
//             return this;
//         }
// 
//         public Builder body(Body body) {
//             this.body = body;
//             return this;
//         }
// 
//         public Builder tag(Object tag) {
//             this.tag = tag;
//             return this;
//         }
// 
//         public HttpRequest build() {
//             return new HttpRequest(method, url, headers, body, tag);
//         }
//     }
// 
// 
//     public static class DefaultFactory<E extends Exception> implements Factory<E> {
// 
//         @NotNull
//         @Override
//         public HttpRequest create(Endpoint endpoint, RestRequest requestInfo,
//                 Authorization authorization, RestConverter.Factory<E> converterFactory) throws E,
//                 RestConverter.ConvertException, IOException {
//             final String url = Endpoint.constructUrl(endpoint.getUrl(), requestInfo);
//             MultiValueMap<String> headers = requestInfo.getHeaders();
//             if (headers == null) {
//                 headers = new MultiValueMap<>();
//             }
//             if (authorization != null && authorization.hasAuthorization()) {
//                 headers.add("Authorization", authorization.getHeader(endpoint, requestInfo));
//             }
//             return new HttpRequest(requestInfo.getMethod(), url, headers, requestInfo.getBody(converterFactory), null);
//         }
//     }
// 
//     /**
//      * Created by mariotaku on 15/5/25.
//      */
//     public interface Factory<E extends Exception> {
//         @NotNull
//         HttpRequest create(Endpoint endpoint, RestRequest info, Authorization authorization,
//                 RestConverter.Factory<E> converterFactory) throws E, RestConverter.ConvertException, IOException;
//     }
// }
// 
// Path: library/src/main/java/org/mariotaku/restfu/http/HttpResponse.java
// public abstract class HttpResponse implements Closeable {
//     public abstract int getStatus();
// 
//     public abstract MultiValueMap<String> getHeaders();
// 
//     public abstract Body getBody();
// 
//     public String getHeader(String name) {
//         if (name == null) throw new NullPointerException();
//         return getHeaders().getFirst(name);
//     }
// 
//     public List<String> getHeaders(String name) {
//         if (name == null) throw new NullPointerException();
//         return getHeaders().get(name);
//     }
// 
//     /**
//      * Returns true if the code is in [200..300), which means the request was
//      * successfully received, understood, and accepted.
//      *
//      * @return True if HTTP response is successful response
//      */
//     public boolean isSuccessful() {
//         final int status = getStatus();
//         return status >= 200 && status < 300;
//     }
// 
//     @Override
//     public String toString() {
//         return "HTTP " + getStatus();
//     }
// }


// Path: library/src/main/java/org/mariotaku/restfu/exception/RestException.java
import org.mariotaku.restfu.http.HttpRequest;
import org.mariotaku.restfu.http.HttpResponse;

/*
 * Copyright (c) 2015 mariotaku
 *
 * 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 org.mariotaku.restfu.exception;


/**
 * Created by mariotaku on 15/2/7.
 */
public class RestException extends RuntimeException {

    private HttpRequest request;
    private HttpResponse response;

    public RestException(String message, Throwable cause) {
        super(message, cause);
    }

    public RestException(String message) {
        super(message);
    }

    public RestException() {
    }

    public RestException(Throwable cause) {
        super(cause);
    }

    @Override
    public String toString() {
        return "RestException{" +
                "response=" + response +
                "} " + super.toString();
    }

    public HttpRequest getRequest() {
        return request;
    }

    public void setRequest(final HttpRequest request) {