/*
 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
 *
 * 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 com.palantir.remoting2.servers.jersey;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.palantir.logsafe.SafeArg;
import com.palantir.remoting2.errors.RemoteException;
import com.palantir.remoting2.errors.SerializableError;
import java.util.UUID;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Provider
final class RemoteExceptionMapper implements ExceptionMapper<RemoteException> {

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

    @Override
    public Response toResponse(RemoteException exception) {
        String errorId = UUID.randomUUID().toString();

        Status status = Status.fromStatusCode(exception.getStatus());

        // here in the client, log responses that indicate client error (4xx) at higher level than server error (5xx)
        if (Status.Family.CLIENT_ERROR.equals(status.getFamily())) {
            log.error("Received response status code {} from server handling request. errorId: {}",
                    SafeArg.of("statusCode", status.getStatusCode()),
                    SafeArg.of("errorId", errorId),
                    exception);
        } else {
            log.info("Received response status code {} from server handling request. errorId: {}",
                    SafeArg.of("statusCode", status.getStatusCode()),
                    SafeArg.of("errorId", errorId),
                    exception);
        }

        SerializableError error = exception.getRemoteException();
        ResponseBuilder builder = Response.status(status);
        try {
            builder.type(MediaType.APPLICATION_JSON);
            String json = JsonExceptionMapper.MAPPER.writeValueAsString(error);
            builder.entity(json);
        } catch (RuntimeException | JsonProcessingException e) {
            log.warn("Unable to translate exception to json for request {}", SafeArg.of("errorId", errorId), e);
            // simply write out the exception message
            builder = Response.status(status);
            builder.type(MediaType.TEXT_PLAIN);
            builder.entity(error.getMessage());
        }
        return builder.build();
    }
}

@@ -1594,29 +1594,9 @@
  // 
-here in the client, l
+L
 og r

Fix comment in RemoteExceptionMapper (#461)