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

Question: Network shutdown case #177

Open
pravosleva opened this issue Dec 29, 2021 · 0 comments
Open

Question: Network shutdown case #177

pravosleva opened this issue Dec 29, 2021 · 0 comments

Comments

@pravosleva
Copy link

pravosleva commented Dec 29, 2021

Should request be retried when network disconnected? (No retries. Why?)

изображение

// api method:

async api({ url, data, cancelToken }: { url: string; data: any, cancelToken: CancelToken }): Promise<any> {
  const result = await this.axiosInstance({
    method: 'POST',
    url: `/chat/api${url}`,
    data,
    // mode: 'cors',
    cancelToken,
  })
    // .then((res: any) => res)
    .then(
      this.universalAxiosResponseHandler(({ data }) => {
        // console.log(data)
        return data?.ok === true || data?.ok === false // NOTE: API like smartprice
      })
    )
    .catch((err: any) => {
      if (axios.isCancel(err)) {
        console.log('Request canceled', err.message)
      } else {
        console.log(err)
      }
      return { isOk: false, message: err.message || 'No err.message', res: null }
    })

  // console.log(result) // { isOk: true, res: { ok: true, _originalBody: { username: 'pravosleva', chatId: 432590698 } } }

  if (result.isOk && !!result.res) {
    return Promise.resolve(result.res)
  }
  return Promise.reject(this.getErrorMsg(result))
}
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