-
Notifications
You must be signed in to change notification settings - Fork 0
Harmonize exceptions handling #129
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 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e4c27c6
Harmonize exceptions handling
9e42f08
Useless newline
b4fbd51
Newline
1a96428
Merge main
10bcb03
Remove business error codes
c7c1f02
Merge main
8b863cb
Mutualize RestResponseEntityExceptionHandler
5302fc2
Implements local RestResponseEntityExceptionHandler derived from Type…
35ddf1f
Rename commom handler to ComputationRestResponseEntityExceptionHandler
f7c4bec
Implements separation of business and misc exceptions handlers
97c12ea
Rename handlers and make them handle their own exceptions to avoid co…
81debfe
Remove BaseExceptionHandler from scan
c720afd
Upgrade ws-commons to 1.34.0
14332be
Move overrides to dependencyManagement
748b78d
Reinstate comment
82b53da
Upgrade computation
e9425ee
Authorship
071807f
Upgrade Filter lib and autowire restTemplateBuilder to FilterService
39fa010
Copyright and add handlers tests
c1e1ff8
Merge branch 'main' into harmonize_exceptions_handling
Meklo 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
29 changes: 29 additions & 0 deletions
29
src/main/java/org/gridsuite/voltageinit/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,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/. | ||
| */ | ||
| package org.gridsuite.voltageinit.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:voltage-init-server}") String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| @Override | ||
| public String serverName() { | ||
| return name; | ||
| } | ||
| } |
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
20 changes: 20 additions & 0 deletions
20
src/main/java/org/gridsuite/voltageinit/server/error/VoltageInitBusinessErrorCode.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,20 @@ | ||
| package org.gridsuite.voltageinit.server.error; | ||
|
|
||
| import com.powsybl.ws.commons.error.BusinessErrorCode; | ||
|
|
||
| /** | ||
| * @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
| */ | ||
| public enum VoltageInitBusinessErrorCode implements BusinessErrorCode { | ||
| MISSING_FILTER("voltageInit.missingFilter"); | ||
|
|
||
| private final String code; | ||
|
|
||
| VoltageInitBusinessErrorCode(String code) { | ||
| this.code = code; | ||
| } | ||
|
|
||
| public String value() { | ||
| return code; | ||
| } | ||
| } | ||
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
45 changes: 45 additions & 0 deletions
45
src/main/java/org/gridsuite/voltageinit/server/error/VoltageInitExceptionHandler.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,45 @@ | ||
| /** | ||
| * 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.voltageinit.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 VoltageInitExceptionHandler extends AbstractBusinessExceptionHandler<VoltageInitException, VoltageInitBusinessErrorCode> { | ||
| protected VoltageInitExceptionHandler(ServerNameProvider serverNameProvider) { | ||
| super(serverNameProvider); | ||
| } | ||
|
|
||
| @Override | ||
| protected @NonNull VoltageInitBusinessErrorCode getBusinessCode(VoltageInitException e) { | ||
| return e.getBusinessErrorCode(); | ||
| } | ||
|
|
||
| @Override | ||
| protected HttpStatus mapStatus(VoltageInitBusinessErrorCode businessErrorCode) { | ||
| return switch (businessErrorCode) { | ||
| case MISSING_FILTER -> HttpStatus.INTERNAL_SERVER_ERROR; | ||
| }; | ||
| } | ||
|
|
||
| @ExceptionHandler(VoltageInitException.class) | ||
| protected ResponseEntity<PowsyblWsProblemDetail> handleVoltageInitException( | ||
| VoltageInitException 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
23 changes: 23 additions & 0 deletions
23
src/test/java/org/gridsuite/voltageinit/server/PropertyServerNameProviderTest.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,23 @@ | ||
| /** | ||
| * 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.voltageinit.server; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
| */ | ||
| class PropertyServerNameProviderTest { | ||
|
|
||
| @Test | ||
| void returnsProvidedName() { | ||
| PropertyServerNameProvider provider = new PropertyServerNameProvider("custom-server"); | ||
| assertThat(provider.serverName()).isEqualTo("custom-server"); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/test/java/org/gridsuite/voltageinit/server/VoltageInitBusinessErrorCodeTest.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,24 @@ | ||
| /** | ||
| * 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.voltageinit.server; | ||
|
|
||
| import org.gridsuite.voltageinit.server.error.VoltageInitBusinessErrorCode; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.EnumSource; | ||
|
|
||
| import static org.gridsuite.voltageinit.utils.assertions.Assertions.assertThat; | ||
|
|
||
| /** | ||
| * @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
| */ | ||
| class VoltageInitBusinessErrorCodeTest { | ||
| @ParameterizedTest | ||
| @EnumSource(VoltageInitBusinessErrorCode.class) | ||
| void valueMatchesEnumName(VoltageInitBusinessErrorCode code) { | ||
| assertThat(code.value()).startsWith("voltageInit."); | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.