Skip to content

Avoid IllegalArgumentException for custom error type in ResponseMapGraphQlResponse #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
richterdg92 opened this issue Jan 30, 2025 · 1 comment
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@richterdg92
Copy link

richterdg92 commented Jan 30, 2025

I can not use there own ErrorClassification

java.lang.IllegalArgumentException: No enum constant org.springframework.graphql.execution.ErrorType.EntityNotFound

	at java.base/java.lang.Enum.valueOf(Enum.java:293)
	at org.springframework.graphql.execution.ErrorType.valueOf(ErrorType.java:30)
	at org.springframework.graphql.client.ResponseMapGraphQlResponse$MapResponseError.getErrorType(ResponseMapGraphQlResponse.java:180)

If i use this guide

class HeaderInterceptor implements WebGraphQlInterceptor { 

    @Override
    public Mono<WebGraphQlResponse> intercept(WebGraphQlRequest request, Chain chain) {
        String value = request.getHeaders().getFirst("myHeader");
        request.configureExecutionInput((executionInput, builder) ->
                builder.graphQLContext(Collections.singletonMap("myHeader", value)).build());
        return chain.next(request);
    }
}

and then throw GraphQLError with custom type

public class CustomExceptionResolver extends DataFetcherExceptionResolverAdapter

My type:


public enum CustomErrorType implements ErrorClassification {
    ENTITY_NOT_FOUND("EntityNotFound"),
    ACCESS_DENIED("AccessDenied");

    private final String errorClassification;

    CustomErrorType(String errorClassification) {
        this.errorClassification = errorClassification;
    }

    @Override
    public String toString() {
        return errorClassification;
    }
}

I'm getting this exception :(

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 30, 2025
@richterdg92 richterdg92 changed the title Change try into getErrorType Exception ResponseMapGraphQlResponse:getErrorType Jan 30, 2025
@rstoyanchev rstoyanchev self-assigned this Feb 12, 2025
@rstoyanchev rstoyanchev added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 12, 2025
@rstoyanchev rstoyanchev added this to the 1.3.4 milestone Feb 12, 2025
@rstoyanchev
Copy link
Contributor

We can't deserialize to a custom enum type on the client side, but we can use ErrorClassification#errorClassification, so at least it returns something and doesn't fail.

@rstoyanchev rstoyanchev changed the title Exception ResponseMapGraphQlResponse:getErrorType Avoid IllegalArgumentException for custom error type in ResponseMapGraphQlResponse Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants