spring-projects / spring-projects/spring-data-rest

When an exception is thrown it is not getting returned in JSON even with AnnotationMethodHandlerExceptionResolver

Open
#84 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Here is what i have in my application config.
The response type is always set to text/html when an exception is thrown

@Bean
public StringHttpMessageConverter stringHttpMessageConverter() {
    return new StringHttpMessageConverter();
}

@Bean
public MappingJacksonHttpMessageConverter jsonHttpMessageConverter() {
    return new MappingJacksonHttpMessageConverter();
}

@Bean
public AnnotationMethodHandlerExceptionResolver methodHandlerExceptionResolver() {
    AnnotationMethodHandlerExceptionResolver annotationMethodHandlerExceptionResolver = new
            AnnotationMethodHandlerExceptionResolver();
    annotationMethodHandlerExceptionResolver.setOrder(1);
    HttpMessageConverter[] messageConvertersList = {jsonHttpMessageConverter()};
    annotationMethodHandlerExceptionResolver.setMessageConverters(messageConvertersList);
    return annotationMethodHandlerExceptionResolver;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the application configuration shown in the issue, especially AnnotationMethodHandlerExceptionResolver and its configured message converters. Reproduce an exception response and inspect why its content type is text/html; done means the exception response is returned as JSON when the resolver is configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.