Bad Request error handling issue

Open Beginner friendly
#3 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
64/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
java, spring-boot
Domain
api, backend

Research direction

Start by locating GlobalControllerExceptionhandler and review how missing required REST parameters are currently handled. Check the existing BadRequestException handling and add coverage for MissingRequestValueException as described in the issue. Done means a request missing a required parameter is captured and returns a 400 response with HttpErrorInfo.

Written by the indexing model from the issue text.

Description

If there's no required parameter from rest call, the GlobalControllerExceptionhandler will never capture it since BadQuestException is never instantiated and thrown. To capture 400 error, you have to do this (using MissingRequestValueException):

@ResponseStatus(BAD_REQUEST)
@ExceptionHandler(MissingRequestValueException.class)
public @ResponseBody HttpErrorInfo handleBadRequestExceptions(
ServerHttpRequest request, MissingRequestValueException ex) {
return createHttpErrorInfo(BAD_REQUEST, request, ex);
}

Dominant language
Java
Stars
47
Forks
35
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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.

More from PacktPublishing/Microservices-with-Spring-Boot-and-Spring-Cloud-Fourth-Edition

All issues in PacktPublishing/Microservices-with-Spring-Boot-and-Spring-Cloud-Fourth-Edition

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.