// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/BadRequestException.java
// public class BadRequestException extends DsmWebApiErrorException {
// 
//     public BadRequestException(String message, DsmWebApiResponseError error) {
//         super(message, error);
//     }
// }
// 
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/DsmWebApiErrorException.java
// public class DsmWebApiErrorException extends DsmWebApiClientException {
// 
//     private final DsmWebApiResponseError error;
// 
//     public DsmWebApiErrorException(String message, DsmWebApiResponseError error) {
//         super(message);
//         this.error = error;
//     }
// 
//     public DsmWebApiErrorException(String message, Throwable cause, DsmWebApiResponseError error) {
//         super(message, cause);
//         this.error = error;
//     }
// 
//     public DsmWebApiErrorException(Throwable cause, DsmWebApiResponseError error) {
//         super(cause);
//         this.error = error;
//     }
// 
//     public DsmWebApiResponseError getError() {
//         return error;
//     }
// }
// 
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/PermissionDeniedException.java
// public class PermissionDeniedException extends DsmWebApiErrorException {
// 
//     public PermissionDeniedException(DsmWebApiResponseError error) {
//         super("The logged in session does not have permission", error);
//     }
// }
// 
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/SessionExpiredException.java
// public class SessionExpiredException extends DsmWebApiErrorException {
// 
//     public SessionExpiredException(String message, DsmWebApiResponseError error) {
//         super(message, error);
//     }
// }
// 
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/UnknownErrorException.java
// public class UnknownErrorException extends DsmWebApiErrorException {
// 
//     public UnknownErrorException(DsmWebApiResponseError error) {
//         super("Unknown error", error);
//     }
// }


import com.github.gauthierj.dsm.webapi.client.exception.BadRequestException;
import com.github.gauthierj.dsm.webapi.client.exception.DsmWebApiErrorException;
import com.github.gauthierj.dsm.webapi.client.exception.PermissionDeniedException;
import com.github.gauthierj.dsm.webapi.client.exception.SessionExpiredException;
import com.github.gauthierj.dsm.webapi.client.exception.UnknownErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
    }

    private <T extends DsmWebapiResponse<?>> void handleFailure(DsmWebapiRequest request, ErrorHandler errorHandler, T response) {
        if(!response.isSuccess()) {
            int code = response.getError().getCode();
            handleGenericErrors(response);
            handleSpecificErrorsIfNeeded(request, errorHandler, response);
            throw new DsmWebApiErrorException(String.format("An unexpected error has occured: %s", code), response.getError());
        }
    }

    private <T extends DsmWebapiResponse<?>> void handleGenericErrors(T response) {
        if(!response.isSuccess()) {
            DsmWebApiResponseError error = response.getError();
            switch (error.getCode()) {
                case GenericErrorCodes.ERROR_CODE_UNKNOWN_ERROR:
                    throw new UnknownErrorException(error);
                case GenericErrorCodes.ERROR_CODE_NO_PARAMETER:
                    throw new BadRequestException("No parameter of API, method or version", error);
                case GenericErrorCodes.ERROR_CODE_API_DOES_NOT_EXISTS:
                    throw new BadRequestException("The requested API does not exist", error);
                case GenericErrorCodes.ERROR_CODE_METHOD_DOES_NOT_EXISTS:
                    throw new BadRequestException("The requested method does not exist", error);
                case GenericErrorCodes.ERROR_CODE_VERSION_DOES_NOT_SUPPORT_FEATURE:
                    throw new BadRequestException("The requested version does not support the functionality", error);
                case GenericErrorCodes.ERROR_CODE_PERMISSION_DENIED:
                    throw new PermissionDeniedException(error);
                case GenericErrorCodes.ERROR_CODE_SESSION_TIMEOUT:
                    throw new SessionExpiredException("Session timeout", error);
                case GenericErrorCodes.ERROR_CODE_DUPLICATE_LOGIN:
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/BadRequestException.java
// public class BadRequestException extends DsmWebApiErrorException {
// 
//     public BadRequestException(String message, DsmWebApiResponseError error) {
//         super(message, error);
//     }
// }
// 
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/DsmWebApiErrorException.java
// public class DsmWebApiErrorException extends DsmWebApiClientException {
// 
//     private final DsmWebApiResponseError error;
// 
//     public DsmWebApiErrorException(String message, DsmWebApiResponseError error) {
//         super(message);
//         this.error = error;
//     }
// 
//     public DsmWebApiErrorException(String message, Throwable cause, DsmWebApiResponseError error) {
//         super(message, cause);
//         this.error = error;
//     }
// 
//     public DsmWebApiErrorException(Throwable cause, DsmWebApiResponseError error) {
//         super(cause);
//         this.error = error;
//     }
// 
//     public DsmWebApiResponseError getError() {
//         return error;
//     }
// }
// 
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/PermissionDeniedException.java
// public class PermissionDeniedException extends DsmWebApiErrorException {
// 
//     public PermissionDeniedException(DsmWebApiResponseError error) {
//         super("The logged in session does not have permission", error);
//     }
// }
// 
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/SessionExpiredException.java
// public class SessionExpiredException extends DsmWebApiErrorException {
// 
//     public SessionExpiredException(String message, DsmWebApiResponseError error) {
//         super(message, error);
//     }
// }
// 
// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/exception/UnknownErrorException.java
// public class UnknownErrorException extends DsmWebApiErrorException {
// 
//     public UnknownErrorException(DsmWebApiResponseError error) {
//         super("Unknown error", error);
//     }
// }


// Path: dsm-webapi-client-core/src/main/java/com/github/gauthierj/dsm/webapi/client/DsmWebapiClientImpl.java
import com.github.gauthierj.dsm.webapi.client.exception.BadRequestException;
import com.github.gauthierj.dsm.webapi.client.exception.DsmWebApiErrorException;
import com.github.gauthierj.dsm.webapi.client.exception.PermissionDeniedException;
import com.github.gauthierj.dsm.webapi.client.exception.SessionExpiredException;
import com.github.gauthierj.dsm.webapi.client.exception.UnknownErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;

    }

    private <T extends DsmWebapiResponse<?>> void handleFailure(DsmWebapiRequest request, ErrorHandler errorHandler, T response) {
        if(!response.isSuccess()) {
            int code = response.getError().getCode();
            handleGenericErrors(response);
            handleSpecificErrorsIfNeeded(request, errorHandler, response);
            throw new DsmWebApiErrorException(String.format("An unexpected error has occured: %s", code), response.getError());
        }
    }

    private <T extends DsmWebapiResponse<?>> void handleGenericErrors(T response) {
        if(!response.isSuccess()) {
            DsmWebApiResponseError error = response.getError();
            switch (error.getCode()) {
                case GenericErrorCodes.ERROR_CODE_UNKNOWN_ERROR:
                    throw new UnknownErrorException(error);
                case GenericErrorCodes.ERROR_CODE_NO_PARAMETER:
                    throw new BadRequestException("No parameter of API, method or version", error);
                case GenericErrorCodes.ERROR_CODE_API_DOES_NOT_EXISTS:
                    throw new BadRequestException("The requested API does not exist", error);
                case GenericErrorCodes.ERROR_CODE_METHOD_DOES_NOT_EXISTS:
                    throw new BadRequestException("The requested method does not exist", error);
                case GenericErrorCodes.ERROR_CODE_VERSION_DOES_NOT_SUPPORT_FEATURE:
                    throw new BadRequestException("The requested version does not support the functionality", error);
                case GenericErrorCodes.ERROR_CODE_PERMISSION_DENIED:
                    throw new PermissionDeniedException(error);
                case GenericErrorCodes.ERROR_CODE_SESSION_TIMEOUT:
                    throw new SessionExpiredException("Session timeout", error);
                case GenericErrorCodes.ERROR_CODE_DUPLICATE_LOGIN:
                    throw new SessionExpiredException("Session interrupted by duplicate login", error);