Skip to content

How To Set A Timeout For fetchBaseQuery #2079

Answered by phryneas
vanenshi asked this question in Q&A
Discussion options

You must be logged in to vote

Hmm, by wrapping fetchBaseQuery:

const baseBq = fetchBaseQuery(options);
const baseQuery = (
    args: string | FetchArgs,
    api: BaseQueryApi,
    extraOptions: { timeout?: number }) => {
    return Promise.race([
      baseBq(args, api, extraOptions),
      new Promise(resolve => setTimeout(() => resolve({ error: "timed out" }), extraOptions.timeout ?? 10000)
    ])
}

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@vanenshi
Comment options

@phryneas
Comment options

@wootencl
Comment options

@wootencl
Comment options

Answer selected by vanenshi
Comment options

You must be logged in to vote
1 reply
@bravo-stack
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants