Skip to content

Commit 2189227

Browse files
downgraded to java 17
1 parent a79d174 commit 2189227

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ all can be done with zero custom code but by specifying error details in `proper
4949

5050
## Installation
5151

52-
> **Current version: 1.8** Refer to [Release notes](https://github.com/officiallysingh/spring-boot-problem-handler/releases/tag/1.7) while upgrading
52+
> **Current version: 1.9** Refer to [Release notes](https://github.com/officiallysingh/spring-boot-problem-handler/releases/tag/1.7) while upgrading
5353
5454
Add the `spring-boot-problem-handler` jar to application dependencies. That is all it takes to get a default working
5555
exception handling mechanism in a Spring boot application.
@@ -62,12 +62,12 @@ Maven
6262
<dependency>
6363
<groupId>io.github.officiallysingh</groupId>
6464
<artifactId>spring-boot-problem-handler</artifactId>
65-
<version>1.8</version>
65+
<version>1.9</version>
6666
</dependency>
6767
```
6868
Gradle
6969
```groovy
70-
implementation 'io.github.officiallysingh:spring-boot-problem-handler:1.8'
70+
implementation 'io.github.officiallysingh:spring-boot-problem-handler:1.9'
7171
```
7272

7373
It does all hard part, A lot of advices are out of box available which are autoconfigured as `ControllerAdvice`s

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.officiallysingh</groupId>
88
<artifactId>spring-boot-problem-handler</artifactId>
9-
<version>1.8</version>
9+
<version>1.9</version>
1010
<name>spring-boot-problem-handler</name>
1111
<description>Commons exception handler library</description>
1212
<url>https://github.com/officiallysingh/spring-boot-problem-handler</url>
@@ -31,7 +31,7 @@
3131
</developers>
3232

3333
<properties>
34-
<java.version>21</java.version>
34+
<java.version>17</java.version>
3535
<spring-boot.version>3.2.5</spring-boot.version>
3636
<spring-cloud.version>2023.0.1</spring-cloud.version>
3737
<jakarta.servlet-api.version>6.0.0</jakarta.servlet-api.version>

src/main/java/com/ksoot/problem/spring/advice/application/ApplicationMultiProblemAdviceTrait.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,33 @@ default R handleMultiProblem(final MultiProblem exception, final T request) {
3737
exception.getErrors().stream()
3838
.map(
3939
ex -> {
40-
switch (ex) {
41-
case Problem problem -> {
42-
return problem;
43-
}
44-
case ProblemSupport problemSupport -> {
45-
if (Objects.nonNull(problemSupport.getProblem())) {
46-
return problemSupport.getProblem();
47-
} else {
48-
String errorKey = problemSupport.getErrorKey();
49-
String detailCode = ProblemConstant.DETAIL_CODE_PREFIX + errorKey;
40+
if (ex instanceof Problem problem) {
41+
return problem;
42+
} else if (ex instanceof ProblemSupport problemSupport) {
43+
if (Objects.nonNull(problemSupport.getProblem())) {
44+
return problemSupport.getProblem();
45+
} else {
46+
String errorKey = problemSupport.getErrorKey();
47+
String detailCode = ProblemConstant.DETAIL_CODE_PREFIX + errorKey;
5048

51-
return toProblem(
52-
(Throwable) ex,
53-
problemSupport.getStatus(),
54-
errorKey,
55-
Optional.ofNullable(problemSupport.getDefaultDetail())
56-
.orElse(detailCode),
57-
problemSupport.getDetailArgs(),
58-
Optional.ofNullable(problemSupport.getParameters())
59-
.orElse(Collections.emptyMap()));
60-
}
61-
}
62-
case Throwable throwable -> {
6349
return toProblem(
64-
throwable,
65-
GeneralErrorKey.INTERNAL_SERVER_ERROR,
66-
HttpStatus.INTERNAL_SERVER_ERROR);
50+
(Throwable) ex,
51+
problemSupport.getStatus(),
52+
errorKey,
53+
Optional.ofNullable(problemSupport.getDefaultDetail())
54+
.orElse(detailCode),
55+
problemSupport.getDetailArgs(),
56+
Optional.ofNullable(problemSupport.getParameters())
57+
.orElse(Collections.emptyMap()));
6758
}
68-
case null, default ->
69-
throw new IllegalStateException(
70-
"MultiProblem contain illegal instance: " + ex);
59+
} else if (ex instanceof Throwable throwable) {
60+
return toProblem(
61+
throwable,
62+
GeneralErrorKey.INTERNAL_SERVER_ERROR,
63+
HttpStatus.INTERNAL_SERVER_ERROR);
64+
} else {
65+
throw new IllegalStateException(
66+
"MultiProblem contain illegal instance: " + ex);
7167
}
7268
})
7369
.toList());

0 commit comments

Comments
 (0)