-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed7f19a
commit 8eabe7b
Showing
20 changed files
with
128 additions
and
101 deletions.
There are no files selected for viewing
This file contains 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
4 changes: 2 additions & 2 deletions
4
src/main/java/it/gov/pagopa/common/web/exception/EmdEncryptionException.java
This file contains 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 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 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 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
26 changes: 15 additions & 11 deletions
26
src/main/java/it/gov/pagopa/onboarding/citizen/configuration/ExceptionMap.java
This file contains 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 |
---|---|---|
@@ -1,37 +1,41 @@ | ||
package it.gov.pagopa.onboarding.citizen.configuration; | ||
|
||
|
||
import it.gov.pagopa.common.web.exception.ClientException; | ||
import it.gov.pagopa.common.web.exception.ClientExceptionWithBody; | ||
import it.gov.pagopa.onboarding.citizen.constants.OnboardingCitizenConstants; | ||
import it.gov.pagopa.onboarding.citizen.constants.CitizenConstants; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
import java.util.function.Function; | ||
|
||
@Configuration | ||
@Slf4j | ||
public class ExceptionMap { | ||
|
||
private final Map<String, Supplier<RuntimeException>> exMap = new HashMap<>(); | ||
private final Map<String, Function<String, ClientException>> exceptions = new HashMap<>(); | ||
|
||
public ExceptionMap() { | ||
exMap.put(OnboardingCitizenConstants.ExceptionName.CITIZEN_NOT_ONBOARDED, () -> | ||
exceptions.put(CitizenConstants.ExceptionName.CITIZEN_NOT_ONBOARDED, message -> | ||
new ClientExceptionWithBody( | ||
HttpStatus.NOT_FOUND, | ||
OnboardingCitizenConstants.ExceptionCode.CITIZEN_NOT_ONBOARDED, | ||
OnboardingCitizenConstants.ExceptionMessage.CITIZEN_NOT_ONBOARDED | ||
CitizenConstants.ExceptionCode.CITIZEN_NOT_ONBOARDED, | ||
message | ||
) | ||
); | ||
|
||
} | ||
|
||
public RuntimeException getException(String exceptionKey) { | ||
if (exMap.containsKey(exceptionKey)) { | ||
return exMap.get(exceptionKey).get(); | ||
public RuntimeException throwException(String exceptionKey, String message) { | ||
if (exceptions.containsKey(exceptionKey)) { | ||
return exceptions.get(exceptionKey).apply(message); | ||
} else { | ||
throw new IllegalArgumentException(String.format("Exception Name Not Found: %s", exceptionKey)); | ||
log.error("Exception Name Not Found: {}", exceptionKey); | ||
return new RuntimeException(); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains 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 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 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 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 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.