/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.camel.component.servicenow;

import java.io.IOException;
import java.io.InputStream;
import javax.annotation.Priority;
import javax.ws.rs.Priorities;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;

@Provider
@Priority(Priorities.USER)
public class ServiceNowExceptionMapper implements ResponseExceptionMapper<ServiceNowException> {
    private final ObjectMapper mapper;

    public ServiceNowExceptionMapper(ObjectMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public ServiceNowException fromResponse(Response r) {
        int code = r.getStatus();

        try {
            if (code == Response.Status.NOT_FOUND.getStatusCode() ||
                code == Response.Status.BAD_REQUEST.getStatusCode() ||
                code == Response.Status.UNAUTHORIZED.getStatusCode() ||
                code == Response.Status.FORBIDDEN.getStatusCode() ||
                code == Response.Status.METHOD_NOT_ALLOWED.getStatusCode()) {

                ServiceNowException res = mapper.readValue((InputStream)r.getEntity(), ServiceNowException.class);
                return res;
            }
        } catch (IOException e) {
            return new ServiceNowException(e);
        }

        return null;
    }
}

@@ -1539,16 +1539,186 @@
   try %7B%0A
+            // Only ServiceNow known error status codes are mapped%0A            // See http://wiki.servicenow.com/index.php?title=REST_API#REST_Response_HTTP_Status_Codes%0A
         
@@ -2089,33 +2089,14 @@
     
-ServiceNowException res =
+return
  map
@@ -2169,36 +2169,8 @@
 s);%0A
-                return res;%0A
     

Add exception mapping