Retry on Specific Error with Delay and Limit

hi, how can i retry based on the specific error, here if ProxyServerOfflineError is catched then retry the execution again for n times, with some delay and if even after n times, ProxyServerOfflineError is catched then it should fail with ProxyServerOfflineError

Effect.gen(function* () {
        let ssrHeaders: Record<string, string> = {}

        if (import.meta.server) {
          tryUseNuxtApp()?.runWithContext(() => {
            ssrHeaders = useRequestHeaders()
          })
        }

        console.log('making request')
        const response = yield * httpClient.execute((function () {
          const requestWithHeaders = (import.meta.server ? HttpClientRequest.setHeaders(ssrHeaders)(request) : request)
          return requestWithHeaders
        })())

        if ([502, 503, 504].includes(response.status)) {
          return yield * Effect.fail(new ProxyServerOfflineError({ message: 'The proxy server is offline. Please try again later.' }))
        }

        // ...rest
      }).pipe(
        Effect.scoped,
        Effect.catchTags({
          RequestError: (error) => {
            // ... handle for request error
          },
        }),
      )
Was this page helpful?