Skip to content
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

Add RequestError and GraphQLError types to indicate server failure and graphql failure. #95

Conversation

zhenlu
Copy link
Contributor

@zhenlu zhenlu commented Apr 11, 2024

Fixes LIG-5257

@zhenlu zhenlu marked this pull request as ready for review April 11, 2024 22:21
Copy link
Contributor Author

zhenlu commented Apr 11, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @zhenlu and the rest of your teammates on Graphite Graphite

@zhenlu zhenlu requested a review from jklein24 April 11, 2024 22:21
requester/requester.go Outdated Show resolved Hide resolved
@zhenlu zhenlu force-pushed the 04-11-add_requesterror_and_graphqlerror_types_to_indicate_server_failure_and_graphql_failure branch 2 times, most recently from 30f36bb to f8a6768 Compare April 11, 2024 22:29
@zhenlu zhenlu requested a review from mgorven April 11, 2024 22:29
Copy link
Contributor

@jklein24 jklein24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgorven can correct me if I'm wrong, but I'm not sure if this totally solves what they're looking for. The most important piece is being able to tell "is this my fault or lightspark's fault and should I retry". @mgorven is it true that anything with an extension is likely to be a non-retryable user error?

@zhenlu
Copy link
Contributor Author

zhenlu commented Apr 11, 2024

I think the RequestError will be the things for them to retry. GraphQLError is the error returned from graphql. All other errors are the errors with their code.

I don't think they should retry on GraphQLError here but it did indicate either side have a bug in code that needs to be fixed.

@mgorven
Copy link
Contributor

mgorven commented Apr 11, 2024

@mgorven can correct me if I'm wrong, but I'm not sure if this totally solves what they're looking for. The most important piece is being able to tell "is this my fault or lightspark's fault and should I retry". @mgorven is it true that anything with an extension is likely to be a non-retryable user error?

It's mostly but not completely true. There are a few cases where we have an extension but it's not necessarily the user's fault (exception classes here which inherit directly from ExternalException, currently NoRoutes and CardPaymentError).

I don't think they should retry on GraphQLError here but it did indicate either side have a bug in code that needs to be fixed.

In principal you're right, but in practice I think customers might want to. e.g. if sparkcore fails to communicate with sparknode because it's restarting that would surface as a graphql error (with no error_name).

@zhenlu
Copy link
Contributor Author

zhenlu commented Apr 11, 2024

So basically:
RequestError: should retry
GraphQLError with empty Type: could retry
Other GraphQLError: don't retry.

@mgorven do you think they can retry on NoRoutes and CardPaymentError? If so I think we need to add a boolean field in the GraphQLError to indicate which one can be retried.

@mgorven
Copy link
Contributor

mgorven commented Apr 11, 2024

@mgorven do you think they can retry on NoRoutes and CardPaymentError? If so I think we need to add a boolean field in the GraphQLError to indicate which one can be retried.

CardPaymentError is only used for billing, so not relevant for the SDK. I don't think that retrying NoRoute is going to help (if routefinder can't find a route it's not going to have one a few seconds later).

@zhenlu
Copy link
Contributor Author

zhenlu commented Apr 11, 2024

I can probably break the GraphQLError into two separate ones so one can retry while the other cannot.

@zhenlu zhenlu force-pushed the 04-11-add_requesterror_and_graphqlerror_types_to_indicate_server_failure_and_graphql_failure branch from f8a6768 to 111dc54 Compare April 11, 2024 23:16
@zhenlu
Copy link
Contributor Author

zhenlu commented Apr 11, 2024

RequestError: should retry
GraphQLInternalError: could retry
GraphQLError: don't retry

@zhenlu zhenlu requested a review from jklein24 April 11, 2024 23:18
@jklein24
Copy link
Contributor

RequestError: should retry GraphQLInternalError: could retry GraphQLError: don't retry

Can we document (in code) the error structs to this effect so that callers can see what to do with each type?

@zhenlu zhenlu force-pushed the 04-11-add_requesterror_and_graphqlerror_types_to_indicate_server_failure_and_graphql_failure branch from 111dc54 to 8184abc Compare April 11, 2024 23:35
"strings"
"time"

lightspark "github.com/lightsparkdev/go-sdk"
)

// RequestError indicates that a request to the Lightspark API failed.
// It could be due to a service outage or a network error.
// The request should be retried if RequestError is returned.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgorven Do we ever return a 401 or 403 or are all http error codes deferred to graphql errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. This error is early returned before parsing graphql response.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but I'm suggesting that really only 5XX errors should be retries, likely not all 4XX errors if our backend is returning those (which it seems to do)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return 401 if an API token is provided but is invalid. It is also possible (but rare) for requests to fail with HTTP 500.

requester/requester.go Outdated Show resolved Hide resolved
@zhenlu zhenlu force-pushed the 04-11-add_requesterror_and_graphqlerror_types_to_indicate_server_failure_and_graphql_failure branch from 25692f7 to e2c76a0 Compare April 12, 2024 00:00
@zhenlu zhenlu merged commit 85b1a95 into main Apr 12, 2024
3 checks passed
@zhenlu zhenlu deleted the 04-11-add_requesterror_and_graphqlerror_types_to_indicate_server_failure_and_graphql_failure branch April 12, 2024 00:01
Copy link
Contributor Author

zhenlu commented Apr 12, 2024

Merge activity

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.

3 participants