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

Correct way of stopping the middleware flow #129

Open
matt-dalton opened this issue Apr 23, 2021 · 0 comments
Open

Correct way of stopping the middleware flow #129

matt-dalton opened this issue Apr 23, 2021 · 0 comments

Comments

@matt-dalton
Copy link

We (possibly weirdly) combine this library with React-Relay-offline to persist queries to local/async storage.

I was trying to prevent the middlewares completing in the event of an error, so that the cache isn't updated. My last middleware function ("last" meaning furthest from the fetch result) looks like this

export const blockCacheOnErrorMiddleware = () => (next: MiddlewareNextFn) => async (
    req: RelayRequestAny
) => {
    const res = await next(req)
    
    // simple fn to grab the error from either a batch or single response
    const error = getFirstErrorFromRes(res)

    if (error) {
        return new Error('Error received from Relay response')
    }

    return res
}

This works great for what I need as far as I can tell. However, I am getting (unsurprisingly) an unhandled Promise exception in the console:

backend.js:32 Possible Unhandled Promise Rejection (id: 0):
RelayNetwork: No data returned for operation `ExampleQuery`, got error(s):
(No errors)

Is there a better way of handling this situation? I had a look at your example source code and couldn't see any similar use-cases

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

No branches or pull requests

1 participant