Skip to content

Conversation

@Vinzius
Copy link
Contributor

@Vinzius Vinzius commented May 2, 2023

New DX:

withAdditionalInterceptors([
  {
    request: ({ request }) => {
      console.log(`Do something with ${JSON.stringify(request)}`)
      return request
    },
    response: ({ response }) => {
      console.log(`Do something with ${JSON.stringify(response)}`)
      return response
    },
    responseError: async ({
      request,
      error,
    }: {
      request: Request
      error: unknown
    }) => {
      console.log(
        `Do something with ${JSON.stringify(request)} and ${JSON.stringify(
          error,
        )}`,
      )
      throw error // or return Promise.resolve(someData)
    },
  },
])

@Vinzius Vinzius force-pushed the feat/error-interceptors branch from 5bbdb50 to ef598a1 Compare May 2, 2023 13:59
@Vinzius Vinzius linked an issue May 3, 2023 that may be closed by this pull request
@philibea
Copy link
Contributor

philibea commented May 4, 2023

Does helper like authenticateWithSessionToken still work with this new pattern ?

@Vinzius Vinzius requested a review from philibea May 5, 2023 15:40
@codecov-commenter
Copy link

codecov-commenter commented May 5, 2023

Codecov Report

Merging #643 (da0058b) into main (e2e09c7) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #643   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           45        45           
  Lines          638       681   +43     
  Branches       130       133    +3     
=========================================
+ Hits           638       681   +43     
Impacted Files Coverage Δ
packages/clients/src/scw/auth.ts 100.00% <ø> (ø)
packages/clients/src/scw/client-settings.ts 100.00% <ø> (ø)
...ages/clients/src/internal/interceptors/composer.ts 100.00% <100.00%> (ø)
...kages/clients/src/internal/interceptors/helpers.ts 100.00% <100.00%> (ø)
packages/clients/src/scw/client-ini-factory.ts 100.00% <100.00%> (ø)
packages/clients/src/scw/client.ts 100.00% <100.00%> (ø)
packages/clients/src/scw/fetch/build-fetcher.ts 100.00% <100.00%> (ø)
...ackages/clients/src/scw/fetch/http-interceptors.ts 100.00% <100.00%> (ø)

@Vinzius Vinzius marked this pull request as ready for review May 9, 2023 09:39
@Vinzius Vinzius changed the title feat: improve interceptors feat: add responseError interceptor May 9, 2023
@Vinzius Vinzius changed the title feat: add responseError interceptor feat: add responseError interceptor May 9, 2023
chambo-e
chambo-e previously approved these changes May 10, 2023
@Vinzius Vinzius added this pull request to the merge queue May 10, 2023
Merged via the queue into main with commit cd58ba4 May 10, 2023
@Vinzius Vinzius deleted the feat/error-interceptors branch May 10, 2023 09:55
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.

Add error interceptors for network calls

6 participants