// Path: westty-protobuf/src/main/java/org/deephacks/westty/protobuf/ProtobufException.java
// public class ProtobufException extends RuntimeException {
// 
//     private static final long serialVersionUID = -7994691832123397253L;
//     private Integer code;
//     private String message;
// 
//     public ProtobufException(String message, Integer code) {
//         this.code = Preconditions.checkNotNull(code);
//         this.message = Preconditions.checkNotNull(message);
//     }
// 
//     public ProtobufException(String message, Integer code, Exception e) {
//         super(e);
//         this.code = Preconditions.checkNotNull(code);
//     }
// 
//     public static void throwBadRequest(String message) {
//         throw new ProtobufException(message, FailureCode.BAD_REQUEST.code);
//     }
// 
//     public static void throwUnauthorized(String message) {
//         throw new ProtobufException(message, FailureCode.UNAUTHORIZED.code);
//     }
// 
//     public static void throwForbidden(String message) {
//         throw new ProtobufException(message, FailureCode.FORBIDDEN.code);
//     }
// 
//     public static void throwNotFound(String message) {
//         throw new ProtobufException(message, FailureCode.NOT_FOUND.code);
//     }
// 
//     public static void throwTimeout(String message) {
//         throw new ProtobufException(message, FailureCode.TIMEOUT.code);
//     }
// 
//     public static void throwConflic(String message) {
//         throw new ProtobufException(message, FailureCode.CONFLICT.code);
//     }
// 
//     public static void throwGone(String message) {
//         throw new ProtobufException(message, FailureCode.GONE.code);
//     }
// 
//     public static void throwTooLarge(String message) {
//         throw new ProtobufException(message, FailureCode.TOO_LARGE.code);
//     }
// 
//     public static void throwInternalError(String message) {
//         throw new ProtobufException(message, FailureCode.INTERNAL_ERROR.code);
//     }
// 
//     public static void throwNotImplemented(String message) {
//         throw new ProtobufException(message, FailureCode.NOT_IMPLEMENTED.code);
//     }
// 
//     public static void throwServiceUnavailable(String message) {
//         throw new ProtobufException(message, FailureCode.BAD_REQUEST.code);
//     }
// 
//     public Integer getCode() {
//         return code;
//     }
// 
//     public String getProtobufMessage() {
//         return message;
//     }
// 
//     @Override
//     public String getMessage() {
//         return codeToString(code) + ": " + message;
//     }
// 
//     static String codeToString(Integer code) {
//         if (code == FailureCode.BAD_REQUEST.code) {
//             return FailureCode.BAD_REQUEST.toString();
//         } else if (code == FailureCode.UNAUTHORIZED.code) {
//             return FailureCode.UNAUTHORIZED.toString();
//         } else if (code == FailureCode.FORBIDDEN.code) {
//             return FailureCode.FORBIDDEN.toString();
//         } else if (code == FailureCode.NOT_FOUND.code) {
//             return FailureCode.NOT_FOUND.toString();
//         } else if (code == FailureCode.TIMEOUT.code) {
//             return FailureCode.TIMEOUT.toString();
//         } else if (code == FailureCode.CONFLICT.code) {
//             return FailureCode.CONFLICT.toString();
//         } else if (code == FailureCode.GONE.code) {
//             return FailureCode.GONE.toString();
//         } else if (code == FailureCode.TOO_LARGE.code) {
//             return FailureCode.TOO_LARGE.toString();
//         } else if (code == FailureCode.INTERNAL_ERROR.code) {
//             return FailureCode.INTERNAL_ERROR.toString();
//         } else if (code == FailureCode.NOT_IMPLEMENTED.code) {
//             return FailureCode.NOT_IMPLEMENTED.toString();
//         } else if (code == FailureCode.SERVICE_UNAVAILABLE.code) {
//             return FailureCode.SERVICE_UNAVAILABLE.toString();
//         } else {
//             return Integer.toString(code);
//         }
//     }
// 
//     public static enum FailureCode {
//         BAD_REQUEST(1), UNAUTHORIZED(2), FORBIDDEN(3), NOT_FOUND(4), TIMEOUT(5), CONFLICT(6), GONE(
//                 6), TOO_LARGE(7), INTERNAL_ERROR(8), NOT_IMPLEMENTED(9), SERVICE_UNAVAILABLE(10);
//         private final Integer code;
// 
//         private FailureCode(Integer code) {
//             this.code = code;
//         }
// 
//         public Integer getCode() {
//             return code;
//         }
//     }
// 
// }


import org.deephacks.westty.protobuf.ProtobufException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
package org.deephacks.westty.tests;



public class ExceptionHandler implements ExceptionMapper<Exception> {
    private static final Logger log = LoggerFactory.getLogger(ExceptionHandler.class);

    public Response toResponse(Exception ex) {
        log.warn("{}", ex.getMessage());
        log.debug("Exception occured", ex);
        Status status = null;
        String message = "";
        if (ex instanceof HttpException) {
            HttpException e = ((HttpException) ex);
            status = e.getCode();
            message = e.getMessage();
        } else if (ex instanceof ProtobufException) {
// Path: westty-protobuf/src/main/java/org/deephacks/westty/protobuf/ProtobufException.java
// public class ProtobufException extends RuntimeException {
// 
//     private static final long serialVersionUID = -7994691832123397253L;
//     private Integer code;
//     private String message;
// 
//     public ProtobufException(String message, Integer code) {
//         this.code = Preconditions.checkNotNull(code);
//         this.message = Preconditions.checkNotNull(message);
//     }
// 
//     public ProtobufException(String message, Integer code, Exception e) {
//         super(e);
//         this.code = Preconditions.checkNotNull(code);
//     }
// 
//     public static void throwBadRequest(String message) {
//         throw new ProtobufException(message, FailureCode.BAD_REQUEST.code);
//     }
// 
//     public static void throwUnauthorized(String message) {
//         throw new ProtobufException(message, FailureCode.UNAUTHORIZED.code);
//     }
// 
//     public static void throwForbidden(String message) {
//         throw new ProtobufException(message, FailureCode.FORBIDDEN.code);
//     }
// 
//     public static void throwNotFound(String message) {
//         throw new ProtobufException(message, FailureCode.NOT_FOUND.code);
//     }
// 
//     public static void throwTimeout(String message) {
//         throw new ProtobufException(message, FailureCode.TIMEOUT.code);
//     }
// 
//     public static void throwConflic(String message) {
//         throw new ProtobufException(message, FailureCode.CONFLICT.code);
//     }
// 
//     public static void throwGone(String message) {
//         throw new ProtobufException(message, FailureCode.GONE.code);
//     }
// 
//     public static void throwTooLarge(String message) {
//         throw new ProtobufException(message, FailureCode.TOO_LARGE.code);
//     }
// 
//     public static void throwInternalError(String message) {
//         throw new ProtobufException(message, FailureCode.INTERNAL_ERROR.code);
//     }
// 
//     public static void throwNotImplemented(String message) {
//         throw new ProtobufException(message, FailureCode.NOT_IMPLEMENTED.code);
//     }
// 
//     public static void throwServiceUnavailable(String message) {
//         throw new ProtobufException(message, FailureCode.BAD_REQUEST.code);
//     }
// 
//     public Integer getCode() {
//         return code;
//     }
// 
//     public String getProtobufMessage() {
//         return message;
//     }
// 
//     @Override
//     public String getMessage() {
//         return codeToString(code) + ": " + message;
//     }
// 
//     static String codeToString(Integer code) {
//         if (code == FailureCode.BAD_REQUEST.code) {
//             return FailureCode.BAD_REQUEST.toString();
//         } else if (code == FailureCode.UNAUTHORIZED.code) {
//             return FailureCode.UNAUTHORIZED.toString();
//         } else if (code == FailureCode.FORBIDDEN.code) {
//             return FailureCode.FORBIDDEN.toString();
//         } else if (code == FailureCode.NOT_FOUND.code) {
//             return FailureCode.NOT_FOUND.toString();
//         } else if (code == FailureCode.TIMEOUT.code) {
//             return FailureCode.TIMEOUT.toString();
//         } else if (code == FailureCode.CONFLICT.code) {
//             return FailureCode.CONFLICT.toString();
//         } else if (code == FailureCode.GONE.code) {
//             return FailureCode.GONE.toString();
//         } else if (code == FailureCode.TOO_LARGE.code) {
//             return FailureCode.TOO_LARGE.toString();
//         } else if (code == FailureCode.INTERNAL_ERROR.code) {
//             return FailureCode.INTERNAL_ERROR.toString();
//         } else if (code == FailureCode.NOT_IMPLEMENTED.code) {
//             return FailureCode.NOT_IMPLEMENTED.toString();
//         } else if (code == FailureCode.SERVICE_UNAVAILABLE.code) {
//             return FailureCode.SERVICE_UNAVAILABLE.toString();
//         } else {
//             return Integer.toString(code);
//         }
//     }
// 
//     public static enum FailureCode {
//         BAD_REQUEST(1), UNAUTHORIZED(2), FORBIDDEN(3), NOT_FOUND(4), TIMEOUT(5), CONFLICT(6), GONE(
//                 6), TOO_LARGE(7), INTERNAL_ERROR(8), NOT_IMPLEMENTED(9), SERVICE_UNAVAILABLE(10);
//         private final Integer code;
// 
//         private FailureCode(Integer code) {
//             this.code = code;
//         }
// 
//         public Integer getCode() {
//             return code;
//         }
//     }
// 
// }


// Path: westty-tests/src/main/java/org/deephacks/westty/tests/ExceptionHandler.java
import org.deephacks.westty.protobuf.ProtobufException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;

package org.deephacks.westty.tests;



public class ExceptionHandler implements ExceptionMapper<Exception> {
    private static final Logger log = LoggerFactory.getLogger(ExceptionHandler.class);

    public Response toResponse(Exception ex) {
        log.warn("{}", ex.getMessage());
        log.debug("Exception occured", ex);
        Status status = null;
        String message = "";
        if (ex instanceof HttpException) {
            HttpException e = ((HttpException) ex);
            status = e.getCode();
            message = e.getMessage();
        } else if (ex instanceof ProtobufException) {
            ProtobufException e = ((ProtobufException) ex);