-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bad request handling #179
Changes from 5 commits
4edf413
637b622
2c11c8c
70ca05c
8118937
903469a
592e370
d4570b7
fb5c76e
77c6a62
b840ae2
93853d0
15ededd
bce723a
55fab02
5135664
d1ee567
0cda7d7
d7cb03e
23572a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ public ResponseEntity<Page<HousekeepingPathResponse>> getAllPaths( | |
@Spec(path = "cleanupTimestamp", params = "deleted_after", spec = GreaterThan.class), | ||
@Spec(path = "creationTimestamp", params = "registered_before", spec = LessThan.class), | ||
@Spec(path = "creationTimestamp", params = "registered_after", spec = GreaterThan.class) }) Specification<HousekeepingPath> spec, | ||
Pageable pageable) { | ||
@ParameterObject Pageable pageable) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added @ParameterObject to the Pageable parameter, this allows Swagger to automatically generate and display pagination parameters (page, size, sort) for /unreferenced-paths. This will make it consistent with /metadata and reduces manual parameter definitions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this for requests params e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The The We already have this in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool thanks for explaning! |
||
return ResponseEntity.ok(housekeepingEntityService.getAllPaths(spec, pageable)); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (C) 2019-2024 Expedia, 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 com.expediagroup.beekeeper.api.error; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.springframework.data.mapping.PropertyReferenceException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@RestControllerAdvice | ||
public class BeekeeperExceptionHandler { | ||
|
||
/** | ||
* Handles invalid sort parameters. | ||
* | ||
* @param ex the exception thrown when an invalid property is referenced | ||
HamzaJugon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param request the HTTP request | ||
* @return a ResponseEntity containing the error response | ||
*/ | ||
|
||
@ExceptionHandler(PropertyReferenceException.class) | ||
public ResponseEntity<ErrorResponse> handlePropertyReferenceException( | ||
PropertyReferenceException ex, HttpServletRequest request) { | ||
HamzaJugon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ErrorResponse errorResponse = new ErrorResponse(); | ||
errorResponse.setTimestamp(LocalDateTime.now().toString()); | ||
errorResponse.setStatus(HttpStatus.BAD_REQUEST.value()); | ||
errorResponse.setError(HttpStatus.BAD_REQUEST.getReasonPhrase()); | ||
errorResponse.setMessage("Invalid sort parameter: " + ex.getMessage()); | ||
errorResponse.setPath(request.getRequestURI()); | ||
|
||
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handles PropertyReferenceException (e.g., invalid sort parameters) globally and returns a custom BAD_REQUEST error response with details. |
||
|
||
} | ||
HamzaJugon marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (C) 2019-2024 Expedia, 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 com.expediagroup.beekeeper.api.error; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Setter | ||
@Getter | ||
public class ErrorResponse { | ||
private String timestamp; | ||
private int status; | ||
private String error; | ||
private String message; | ||
private String path; | ||
} | ||
HamzaJugon marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior it was possible to push to maven central from any branch which can lead to accidental pushes to maven central