Skip to content

Add StatusCode property to GraphQueryRequestException#86

Open
jonasessen wants to merge 1 commit intoLinq2GraphQL:mainfrom
jonasessen:feat/statuscode-on-exception
Open

Add StatusCode property to GraphQueryRequestException#86
jonasessen wants to merge 1 commit intoLinq2GraphQL:mainfrom
jonasessen:feat/statuscode-on-exception

Conversation

@jonasessen
Copy link
Copy Markdown

Problem

GraphQueryRequestException currently embeds the HTTP status code only inside the exception message string:

throw new GraphQueryRequestException($"Http error! Status code {response.StatusCode} Error: {content}", ...);

This means callers who want to handle specific HTTP errors (e.g. 401 Unauthorized vs 503 Service Unavailable) are forced to parse a string, which is fragile and not idiomatic C#.

Solution

Add a structured StatusCode property of type HttpStatusCode to GraphQueryRequestException, populated at the throw site in QueryExecutor.

Callers can now write clean, type-safe error handling:

catch (GraphQueryRequestException ex) when (ex.StatusCode == HttpStatusCode.Unauthorized)
{
    // refresh token and retry
}
catch (GraphQueryRequestException ex) when (ex.StatusCode == HttpStatusCode.ServiceUnavailable)
{
    // back off and retry
}

Changes

File Change
GraphQueryRequestException.cs Add HttpStatusCode StatusCode property and constructor parameter; tighten property accessors to get-only
QueryExecutor.cs Pass response.StatusCode when throwing the exception

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant