-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#29270 Rollback to
CustomGraphQLException
as Base Class
**Reason for Rollback**: - The change to use `GraphQLErrorException` as the base class for `PermissionDeniedGraphQLException` caused a violation of the SonarQube rule "Inheritance tree of classes should not be too deep." - The inheritance tree depth exceeded the allowed limit, leading to maintainability issues flagged by SonarQube.
- Loading branch information
1 parent
2529e1b
commit 5213a35
Showing
2 changed files
with
92 additions
and
7 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
dotCMS/src/main/java/com/dotcms/graphql/exception/CustomGraphQLException.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,75 @@ | ||
package com.dotcms.graphql.exception; | ||
|
||
import graphql.ErrorType; | ||
import graphql.GraphQLError; | ||
import graphql.GraphQLException; | ||
import graphql.language.SourceLocation; | ||
import java.util.Collections; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Custom exception class for GraphQL errors. | ||
* <p> | ||
* This class extends {@link GraphQLException} and implements {@link GraphQLError}, | ||
* allowing for customized error handling in GraphQL applications. | ||
* </p> | ||
* <p> | ||
* By implementing {@link GraphQLError}, this exception can provide additional | ||
* context or metadata about the error, such as locations, extensions, and error types. | ||
* </p> | ||
*/ | ||
public class CustomGraphQLException extends RuntimeException implements GraphQLError { | ||
|
||
/** | ||
* Constructs a new CustomGraphQLException with the specified detail message. | ||
* | ||
* @param message the detail message explaining the reason for the exception. | ||
*/ | ||
public CustomGraphQLException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Provides additional metadata about the error. | ||
* <p> | ||
* This implementation returns an empty map, but subclasses can override this | ||
* method to include custom extensions that provide more information about the error. | ||
* </p> | ||
* | ||
* @return an empty map by default, which can be overridden by subclasses. | ||
*/ | ||
@Override | ||
public Map<String, Object> getExtensions() { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
/** | ||
* Returns the list of source locations related to the error. | ||
* <p> | ||
* This implementation returns an empty list, but subclasses can override this | ||
* method to include the specific locations in the GraphQL query where the error occurred. | ||
* </p> | ||
* | ||
* @return an empty list by default, which can be overridden by subclasses. | ||
*/ | ||
@Override | ||
public List<SourceLocation> getLocations() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
/** | ||
* Returns the type of the error. | ||
* <p> | ||
* This implementation returns {@code null}, but subclasses can override this | ||
* method to provide a specific {@link ErrorType} for the error. | ||
* </p> | ||
* | ||
* @return {@code null} by default, which can be overridden by subclasses. | ||
*/ | ||
@Override | ||
public ErrorType getErrorType() { | ||
return null; | ||
} | ||
} |
24 changes: 17 additions & 7 deletions
24
dotCMS/src/main/java/com/dotcms/graphql/exception/PermissionDeniedGraphQLException.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,17 +1,27 @@ | ||
package com.dotcms.graphql.exception; | ||
|
||
import graphql.GraphqlErrorException; | ||
/** | ||
* Custom exception for permission denial in GraphQL operations. | ||
* This exception is used to indicate that a user does not have the necessary permissions | ||
* to access a specific resource. | ||
*/ | ||
public class PermissionDeniedGraphQLException extends CustomGraphQLException { | ||
|
||
public class PermissionDeniedGraphQLException extends GraphqlErrorException { | ||
private static final String DEFAULT_MESSAGE = "Permission denied: You do not have permission to access this resource."; | ||
|
||
/** | ||
* Constructs a new PermissionDeniedGraphQLException with a specific message. | ||
* | ||
* @param message The detail message to be used. | ||
*/ | ||
public PermissionDeniedGraphQLException(String message) { | ||
super(new Builder().message(message)); | ||
super(message); | ||
} | ||
|
||
/** | ||
* Constructs a new PermissionDeniedGraphQLException with a default message. | ||
*/ | ||
public PermissionDeniedGraphQLException() { | ||
super(new Builder().message("Permission denied: You do not have permission to access this resource.")); | ||
this(DEFAULT_MESSAGE); | ||
} | ||
|
||
} | ||
|
||
|