@@ -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