-
Notifications
You must be signed in to change notification settings - Fork 0
Harmonize exceptions handling #170
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
aa2720d
Harmonize exceptions handling
79bfaa1
Remove dep
7deb2a3
Add ShortcircuitBusinessErrorCodeTest
9c4ef5e
Mutualize INVALID_EXPORT_PARAMS
553d37a
Merge main
d815eda
Actually a technical error
56345b7
Remove business error codes
c1213a6
Merge main
6e3dd15
Fix test
c4cc088
Mutualize RestResponseEntityExceptionHandler
06077d8
Create dedicated package
58baab4
Move ShortCircuitException to new package
a57f1b8
Implements local RestResponseEntityExceptionHandler derived from Type…
88b36a4
Rename class
81940b7
Implements separation of business and misc exceptions handlers
f7801cc
Checkstyle
0947ab1
Checkstyle
a45442b
Rename handlers and make them handle their own exceptions to avoid co…
1b96424
Remove BaseExceptionHandler from scan
c92a5c7
Upgrade ws-commons to 1.34.0
9ecdbc2
Move overrides to dependencyManagement
cdaf380
Upgrade computation
2a34e5b
Authorship
e2e036e
Merge remote-tracking branch 'origin/main' into harmonize_exceptions_…
d90b46e
Upgrade Filter lib and autowire restTemplateBuilder to FilterService
9a40c9f
Checkstyle
aac0785
Copyright and add handlers tests
7d0b314
Merge main
ad9f8b1
Fix import
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/org/gridsuite/shortcircuit/server/PropertyServerNameProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /** | ||
| * Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.shortcircuit.server; | ||
|
|
||
| import com.powsybl.ws.commons.error.ServerNameProvider; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
| */ | ||
| @Component | ||
| public class PropertyServerNameProvider implements ServerNameProvider { | ||
| private final String name; | ||
|
|
||
| public PropertyServerNameProvider(@Value("${spring.application.name:shortcircuit-server}") String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| @Override | ||
| public String serverName() { | ||
| return name; | ||
| } | ||
| } |
29 changes: 0 additions & 29 deletions
29
src/main/java/org/gridsuite/shortcircuit/server/RestResponseEntityExceptionHandler.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 0 additions & 41 deletions
41
src/main/java/org/gridsuite/shortcircuit/server/ShortCircuitException.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/main/java/org/gridsuite/shortcircuit/server/error/ShortCircuitException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /** | ||
| * Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.shortcircuit.server.error; | ||
|
|
||
| import com.powsybl.ws.commons.error.AbstractBusinessException; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.Getter; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * @author David SARTORI <david.sartori_externe at rte-france.com> | ||
| */ | ||
| @Getter | ||
| public class ShortCircuitException extends AbstractBusinessException { | ||
|
|
||
| private final ShortcircuitBusinessErrorCode errorCode; | ||
|
|
||
| public ShortCircuitException(ShortcircuitBusinessErrorCode errorCode, String message) { | ||
| super(Objects.requireNonNull(message, "message must not be null")); | ||
| this.errorCode = Objects.requireNonNull(errorCode, "errorCode must not be null"); | ||
| } | ||
|
|
||
| @NotNull | ||
| @Override | ||
| public ShortcircuitBusinessErrorCode getBusinessErrorCode() { | ||
| return errorCode; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/gridsuite/shortcircuit/server/error/ShortcircuitBusinessErrorCode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| * SPDX-License-Identifier: MPL-2.0 | ||
| */ | ||
| package org.gridsuite.shortcircuit.server.error; | ||
|
|
||
| import com.powsybl.ws.commons.error.BusinessErrorCode; | ||
|
|
||
| /** | ||
| * @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
| */ | ||
| public enum ShortcircuitBusinessErrorCode implements BusinessErrorCode { | ||
| BUS_OUT_OF_VOLTAGE("shortcircuit.busOutOfVoltage"), | ||
| MISSING_EXTENSION_DATA("shortcircuit.missingExtensionData"), | ||
| INCONSISTENT_VOLTAGE_LEVELS("shortcircuit.inconsistentVoltageLevels"),; | ||
|
|
||
| private final String code; | ||
|
|
||
| ShortcircuitBusinessErrorCode(String code) { | ||
| this.code = code; | ||
| } | ||
|
|
||
| public String value() { | ||
| return code; | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
src/main/java/org/gridsuite/shortcircuit/server/error/ShortcircuitExceptionHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /** | ||
| * Copyright (c) 2025, RTE (http://www.rte-france.com) | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.gridsuite.shortcircuit.server.error; | ||
|
|
||
| import com.powsybl.ws.commons.error.AbstractBusinessExceptionHandler; | ||
| import com.powsybl.ws.commons.error.PowsyblWsProblemDetail; | ||
| import com.powsybl.ws.commons.error.ServerNameProvider; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import lombok.NonNull; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ControllerAdvice; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
|
||
| /** | ||
| * @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
| */ | ||
|
|
||
| @ControllerAdvice | ||
| public class ShortcircuitExceptionHandler extends AbstractBusinessExceptionHandler<ShortCircuitException, ShortcircuitBusinessErrorCode> { | ||
| protected ShortcircuitExceptionHandler(ServerNameProvider serverNameProvider) { | ||
| super(serverNameProvider); | ||
| } | ||
|
|
||
| @Override | ||
| protected @NonNull ShortcircuitBusinessErrorCode getBusinessCode(ShortCircuitException e) { | ||
| return e.getBusinessErrorCode(); | ||
| } | ||
|
|
||
| @Override | ||
| protected HttpStatus mapStatus(ShortcircuitBusinessErrorCode businessErrorCode) { | ||
| return switch (businessErrorCode) { | ||
| case BUS_OUT_OF_VOLTAGE, INCONSISTENT_VOLTAGE_LEVELS, MISSING_EXTENSION_DATA -> | ||
| HttpStatus.INTERNAL_SERVER_ERROR; | ||
| }; | ||
| } | ||
|
|
||
| @ExceptionHandler(ShortCircuitException.class) | ||
| protected ResponseEntity<PowsyblWsProblemDetail> handleShortcircuitException( | ||
| ShortCircuitException exception, HttpServletRequest request) { | ||
| return super.handleDomainException(exception, request); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
copyright