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

Bad Request error handling issue

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

Nobody has claimed this yet.

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

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);
}

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.

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.