Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/src/main/java/io/confluent/rest/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.jaxrs.base.JsonParseExceptionMapper;

import io.confluent.rest.exceptions.SuppressedJsonParseExceptionMapper;
import org.apache.kafka.common.config.ConfigException;
import org.eclipse.jetty.jaas.JAASLoginService;
import org.eclipse.jetty.security.ConstraintMapping;
Expand Down Expand Up @@ -497,7 +498,7 @@ public void configureBaseApplication(Configurable<?> config) {
public void configureBaseApplication(Configurable<?> config, Map<String, String> metricTags) {
T restConfig = getConfiguration();

registerJsonProvider(config, restConfig, true);
registerJsonProvider(config, restConfig, restConfig.getBoolean(RestConfig.DEBUG_CONFIG));
registerFeatures(config, restConfig);
registerExceptionMappers(config, restConfig);

Expand Down Expand Up @@ -526,6 +527,8 @@ protected void registerJsonProvider(
config.register(jsonProvider);
if (registerExceptionMapper) {
config.register(JsonParseExceptionMapper.class);
} else {
config.register(SuppressedJsonParseExceptionMapper.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2017 Confluent Inc.
*
* 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 io.confluent.rest.exceptions;

import com.fasterxml.jackson.core.JsonParseException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.ExceptionMapper;

public class SuppressedJsonParseExceptionMapper implements ExceptionMapper<JsonParseException> {
public SuppressedJsonParseExceptionMapper() {}

public Response toResponse(JsonParseException exception) {
return Response.status(Status.BAD_REQUEST)
.entity("Error parsing JSON")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we at least send exception.getMessage()? The user is losing critical information to understand what went wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.type("text/plain")
.build();
}
}