Skip to content

ApplicationException

nimamoosavi edited this page Aug 6, 2021 · 2 revisions

This Service Used for Generate An RunTime Exception Example Service Exception

< R > is the type Of Exception that you can return From Method

Methode

R createApplicationException(String exceptionKey);

this method create An RunTime Exception

exceptionKey this key that fetch from Resource properties And the Object Of Exception Class that you can throw it

R createApplicationException(Message);

message is the Object of message that you must impl it

return the Object Of Exception Class that you can throw it

Notification createApplicationWarning(Message);

message is the Object of message that you must impl it

return the Object Of notification Class

List createApplicationWarning(Message[] messages);

messages is the Object of message that you must impl it

return the Object Of notification Class

R createApplicationException(String exceptionKey, HttpStatus)

this key that fetch from Resource properties

httpStatus is the status of Http Response

R createApplicationException(Message, HttpStatus)

is the Object of message that you must impl it {@link Message}

is the status of Http Response {@link org.springframework.http.HttpStatus}

return the Object Of Exception Class that you can throw it

Example

public BaseDTO<R> findById(@NotNull I id) {
        T t = generalRepository.findById(id).orElseThrow(
                () -> applicationException.createApplicationException(ExceptionEnum.NOTFOUND, HttpStatus.NOT_FOUND)
        );
        return generalMapper.mapBaseObjectToResponse(t);
    }
Clone this wiki locally