-
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.
Merge pull request #4 from MEITREX/more-repo-utils
add more custom exceptions and repository utility
- Loading branch information
Showing
5 changed files
with
120 additions
and
12 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
11 changes: 11 additions & 0 deletions
11
...ain/java/de/unistuttgart/iste/meitrex/common/exception/ExceptionWithGraphQlErrorType.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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.unistuttgart.iste.meitrex.common.exception; | ||
|
||
import graphql.ErrorType; | ||
|
||
/** | ||
* Interface for exceptions that have a {@link ErrorType}. | ||
*/ | ||
public interface ExceptionWithGraphQlErrorType { | ||
|
||
ErrorType getErrorType(); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/de/unistuttgart/iste/meitrex/common/exception/MeitrexNotFoundException.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package de.unistuttgart.iste.meitrex.common.exception; | ||
|
||
import graphql.ErrorType; | ||
import jakarta.persistence.EntityNotFoundException; | ||
|
||
/** | ||
* Exception that is thrown when a resource is not found. | ||
*/ | ||
public class MeitrexNotFoundException extends EntityNotFoundException implements ExceptionWithGraphQlErrorType { | ||
public MeitrexNotFoundException(String entityName, Object id) { | ||
this("Resource " + entityName + " with id " + id + " not found"); | ||
} | ||
|
||
public MeitrexNotFoundException(String reason) { | ||
super(reason); | ||
} | ||
|
||
|
||
@Override | ||
public ErrorType getErrorType() { | ||
return ErrorType.DataFetchingException; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...in/java/de/unistuttgart/iste/meitrex/common/exception/ResourceAlreadyExistsException.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package de.unistuttgart.iste.meitrex.common.exception; | ||
|
||
import graphql.ErrorType; | ||
|
||
/** | ||
* Exception to be thrown when a resource already exists, but it is tried to be created again. | ||
*/ | ||
public class ResourceAlreadyExistsException extends RuntimeException implements ExceptionWithGraphQlErrorType { | ||
public ResourceAlreadyExistsException(String reason) { | ||
super(reason); | ||
} | ||
|
||
public ResourceAlreadyExistsException(String resourceName, Object id) { | ||
this(resourceName + " with id " + id + " already exists."); | ||
} | ||
|
||
public ResourceAlreadyExistsException(Class<?> resourceClass, Object id) { | ||
this(resourceClass.getSimpleName() + " with id " + id + " already exists."); | ||
} | ||
|
||
@Override | ||
public ErrorType getErrorType() { | ||
return ErrorType.ValidationError; | ||
} | ||
} |
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