// Path: src/main/java/com/github/mkopylec/errorest/response/Errors.java
// @JacksonXmlRootElement(localName = "body")
// public class Errors {
// 
//     public static final String EMPTY_ERRORS_ID = "N/A";
// 
//     protected final String id;
//     @JacksonXmlProperty(localName = "error")
//     @JacksonXmlElementWrapper(localName = "errors")
//     protected final List<Error> errors;
// 
//     @JsonCreator
//     public Errors(
//             @JsonProperty("id") @JacksonXmlProperty(localName = "id") String id,
//             @JsonProperty("errors") @JacksonXmlProperty(localName = "Jackson bug workaround") List<Error> errors
//     ) {
//         hasText(id, "Empty errors ID");
//         this.id = id;
//         this.errors = errors == null ? new ErrorsLoggingList() : new ErrorsLoggingList(errors);
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public List<Error> getErrors() {
//         return errors;
//     }
// 
//     public boolean hasErrors() {
//         return !errors.isEmpty();
//     }
// 
//     public boolean containsErrorCode(String code) {
//         return errors.stream().anyMatch(error -> error.hasCode(code));
//     }
// 
//     public boolean containsErrorDescriptions() {
//         return errors.stream().anyMatch(Error::hasDescription);
//     }
// 
//     public boolean containsErrorDescription(String description) {
//         return errors.stream().anyMatch(error -> error.hasDescription(description));
//     }
// 
//     @JsonIgnore
//     public boolean isEmpty() {
//         return EMPTY_ERRORS_ID.equals(id) && !hasErrors();
//     }
// 
//     public void formatErrors(ResponseBodyFormat bodyFormat) {
//         errors.forEach(error -> error.format(bodyFormat));
//     }
// 
//     public static Errors emptyErrors() {
//         return new Errors(EMPTY_ERRORS_ID, emptyList());
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (obj == null) {
//             return false;
//         }
//         if (obj == this) {
//             return true;
//         }
//         if (obj.getClass() != getClass()) {
//             return false;
//         }
//         Errors rhs = (Errors) obj;
//         return new EqualsBuilder()
//                 .append(this.id, rhs.id)
//                 .append(this.errors, rhs.errors)
//                 .isEquals();
//     }
// 
//     @Override
//     public int hashCode() {
//         return new HashCodeBuilder()
//                 .append(id)
//                 .append(errors)
//                 .toHashCode();
//     }
// }
// 
// Path: src/main/java/com/github/mkopylec/errorest/response/Errors.java
// public static Errors emptyErrors() {
//     return new Errors(EMPTY_ERRORS_ID, emptyList());
// }


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.github.mkopylec.errorest.response.Errors;
import org.slf4j.Logger;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.client.HttpStatusCodeException;
import java.io.IOException;
import java.nio.charset.Charset;
import static com.github.mkopylec.errorest.response.Errors.emptyErrors;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML;
package com.github.mkopylec.errorest.exceptions;




public class ExternalHttpRequestException extends HttpStatusCodeException {

    private static final Logger log = getLogger(ExternalHttpRequestException.class);

    protected final HttpMethod method;
    protected final String url;
    protected final ObjectMapper jsonMapper;
    protected final XmlMapper xmlMapper;
    protected Errors errors;

    public ExternalHttpRequestException(HttpMethod method, String url, HttpStatus statusCode, String statusText, HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset, ObjectMapper jsonMapper, XmlMapper xmlMapper) {
        super(statusCode, statusText, responseHeaders, responseBody, responseCharset);
        this.method = method;
        this.url = url;
        this.jsonMapper = jsonMapper;
        this.xmlMapper = xmlMapper;
    }

    public Errors getResponseBodyAsErrors() {
        if (errors != null) {
            return errors;
        }
        errors = parseResponseBody();
        if (errors == null) {
// Path: src/main/java/com/github/mkopylec/errorest/response/Errors.java
// @JacksonXmlRootElement(localName = "body")
// public class Errors {
// 
//     public static final String EMPTY_ERRORS_ID = "N/A";
// 
//     protected final String id;
//     @JacksonXmlProperty(localName = "error")
//     @JacksonXmlElementWrapper(localName = "errors")
//     protected final List<Error> errors;
// 
//     @JsonCreator
//     public Errors(
//             @JsonProperty("id") @JacksonXmlProperty(localName = "id") String id,
//             @JsonProperty("errors") @JacksonXmlProperty(localName = "Jackson bug workaround") List<Error> errors
//     ) {
//         hasText(id, "Empty errors ID");
//         this.id = id;
//         this.errors = errors == null ? new ErrorsLoggingList() : new ErrorsLoggingList(errors);
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public List<Error> getErrors() {
//         return errors;
//     }
// 
//     public boolean hasErrors() {
//         return !errors.isEmpty();
//     }
// 
//     public boolean containsErrorCode(String code) {
//         return errors.stream().anyMatch(error -> error.hasCode(code));
//     }
// 
//     public boolean containsErrorDescriptions() {
//         return errors.stream().anyMatch(Error::hasDescription);
//     }
// 
//     public boolean containsErrorDescription(String description) {
//         return errors.stream().anyMatch(error -> error.hasDescription(description));
//     }
// 
//     @JsonIgnore
//     public boolean isEmpty() {
//         return EMPTY_ERRORS_ID.equals(id) && !hasErrors();
//     }
// 
//     public void formatErrors(ResponseBodyFormat bodyFormat) {
//         errors.forEach(error -> error.format(bodyFormat));
//     }
// 
//     public static Errors emptyErrors() {
//         return new Errors(EMPTY_ERRORS_ID, emptyList());
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (obj == null) {
//             return false;
//         }
//         if (obj == this) {
//             return true;
//         }
//         if (obj.getClass() != getClass()) {
//             return false;
//         }
//         Errors rhs = (Errors) obj;
//         return new EqualsBuilder()
//                 .append(this.id, rhs.id)
//                 .append(this.errors, rhs.errors)
//                 .isEquals();
//     }
// 
//     @Override
//     public int hashCode() {
//         return new HashCodeBuilder()
//                 .append(id)
//                 .append(errors)
//                 .toHashCode();
//     }
// }
// 
// Path: src/main/java/com/github/mkopylec/errorest/response/Errors.java
// public static Errors emptyErrors() {
//     return new Errors(EMPTY_ERRORS_ID, emptyList());
// }


// Path: src/main/java/com/github/mkopylec/errorest/exceptions/ExternalHttpRequestException.java
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.github.mkopylec.errorest.response.Errors;
import org.slf4j.Logger;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.client.HttpStatusCodeException;
import java.io.IOException;
import java.nio.charset.Charset;
import static com.github.mkopylec.errorest.response.Errors.emptyErrors;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML;

package com.github.mkopylec.errorest.exceptions;




public class ExternalHttpRequestException extends HttpStatusCodeException {

    private static final Logger log = getLogger(ExternalHttpRequestException.class);

    protected final HttpMethod method;
    protected final String url;
    protected final ObjectMapper jsonMapper;
    protected final XmlMapper xmlMapper;
    protected Errors errors;

    public ExternalHttpRequestException(HttpMethod method, String url, HttpStatus statusCode, String statusText, HttpHeaders responseHeaders, byte[] responseBody, Charset responseCharset, ObjectMapper jsonMapper, XmlMapper xmlMapper) {
        super(statusCode, statusText, responseHeaders, responseBody, responseCharset);
        this.method = method;
        this.url = url;
        this.jsonMapper = jsonMapper;
        this.xmlMapper = xmlMapper;
    }

    public Errors getResponseBodyAsErrors() {
        if (errors != null) {
            return errors;
        }
        errors = parseResponseBody();
        if (errors == null) {
            return emptyErrors();