• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ExpediaGroup / beekeeper / #505

18 Oct 2024 11:59AM UTC coverage: 86.242% (-0.8%) from 87.068%
#505

push

Hamza Jugon
Adding Exception handling for bad requests

1 of 15 new or added lines in 2 files covered. (6.67%)

1260 of 1461 relevant lines covered (86.24%)

0.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.5
/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java
1
/**
2
 * Copyright (C) 2019-2024 Expedia, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.expediagroup.beekeeper.api.error;
18

19
import javax.servlet.http.HttpServletRequest;
20

21
import org.springframework.data.mapping.PropertyReferenceException;
22
import org.springframework.http.HttpStatus;
23
import org.springframework.http.ResponseEntity;
24
import org.springframework.web.bind.annotation.ExceptionHandler;
25
import org.springframework.web.bind.annotation.RestControllerAdvice;
26

27
import java.time.LocalDateTime;
28

29
@RestControllerAdvice
30
public class BeekeeperExceptionHandler {
1✔
31

32
  /**
33
   * Handles invalid sort parameters.
34
   *
35
   * @param ex      the exception thrown when an invalid property is referenced
36
   * @param request the HTTP request
37
   * @return a ResponseEntity containing the error response
38
   */
39

40
  @ExceptionHandler(PropertyReferenceException.class)
41
  public ResponseEntity<ErrorResponse> handlePropertyReferenceException(
42
      PropertyReferenceException ex, HttpServletRequest request) {
43

NEW
44
    ErrorResponse errorResponse = new ErrorResponse();
×
NEW
45
    errorResponse.setTimestamp(LocalDateTime.now().toString());
×
NEW
46
    errorResponse.setStatus(HttpStatus.BAD_REQUEST.value());
×
NEW
47
    errorResponse.setError(HttpStatus.BAD_REQUEST.getReasonPhrase());
×
NEW
48
    errorResponse.setMessage("Invalid sort parameter: " + ex.getMessage());
×
NEW
49
    errorResponse.setPath(request.getRequestURI());
×
50

NEW
51
    return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
×
52
  }
53

54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc