当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript request.defaults方法代码示例

本文整理汇总了TypeScript中client/request.request.defaults方法的典型用法代码示例。如果您正苦于以下问题:TypeScript request.defaults方法的具体用法?TypeScript request.defaults怎么用?TypeScript request.defaults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在client/request.request的用法示例。


在下文中一共展示了request.defaults方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createPostcodeToCountryClient

 static createPostcodeToCountryClient (): PostcodeToCountryClient {
   return new PostcodeToCountryClient(
     postcodeLookupApiKey,
     request.defaults(requestOptionsOverride)
   )
 }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:6,代码来源:clientFactory.ts

示例2: context

  context('timeouts and retries handling', () => {
    const requestDelayInMillis = 500
    const retryAttempts = 3

    const retryingRequest = request.defaults({
      retryDelay: requestDelayInMillis,
      maxAttempts: retryAttempts
    } as RequestPromiseOptions)

    const claimStoreClient: ClaimStoreClient = new ClaimStoreClient(retryingRequest)

    describe('saveClaim', () => {
      function mockSuccessOnFirstSaveAttempt () {
        mock(`${claimStoreApiUrl}`)
          .post(`/${claimant.id}`)
          .reply(HttpStatus.OK, returnedClaim)
      }

      it('should retrieve a claim that was successfully saved on first attempt with feature toggles', async () => {
        mockSuccessOnFirstSaveAttempt()

        const claim: Claim = await claimStoreClient.saveClaim(claimDraft, claimant, 'admissions')

        expect(claim.claimData).to.deep.equal(new ClaimData().deserialize(expectedClaimData))
      })

      it('should retrieve a claim that was successfully saved on first attempt without feature toggles', async () => {
        mockSuccessOnFirstSaveAttempt()

        const claim: Claim = await claimStoreClient.saveClaim(claimDraft, claimant)

        expect(claim.claimData).to.deep.equal(new ClaimData().deserialize(expectedClaimData))
      })

      function mockTimeoutOnFirstSaveAttemptAndConflictOnSecondOne () {
        mock(`${claimStoreApiUrl}`)
          .post(`/${claimant.id}`)
          .socketDelay(requestDelayInMillis + 10)
        mock(`${claimStoreApiUrl}`)
          .post(`/${claimant.id}`)
          .reply(HttpStatus.CONFLICT, `Duplicate claim for external id ${claimDraftData.externalId}`)
        mock(`${claimStoreApiUrl}`)
          .get(`/${claimDraftData.externalId}`)
          .reply(HttpStatus.OK, returnedClaim)
      }

      it('should retrieve claim saved on first attempt that timed out and caused a 409 on retry', async () => {
        resolveLinkDefendant()
        mockTimeoutOnFirstSaveAttemptAndConflictOnSecondOne()

        const claim: Claim = await claimStoreClient.saveClaim(claimDraft, claimant, 'admissions')

        expect(claim.claimData).to.deep.equal(new ClaimData().deserialize(expectedClaimData))
      })

      function resolveLinkDefendant () {
        mock(`${claimStoreApiUrl}`)
          .put('/defendant/link')
          .reply(HttpStatus.OK)
      }

      function mockInternalServerErrorOnAllAttempts () {
        mock(`${claimStoreApiUrl}`)
          .post(`/${claimant.id}`)
          .times(retryAttempts)
          .reply(HttpStatus.INTERNAL_SERVER_ERROR, 'An unexpected error occurred')
      }

      it('should propagate error responses other than 409', async () => {
        mockInternalServerErrorOnAllAttempts()

        try {
          await claimStoreClient.saveClaim(claimDraft, claimant, 'admissions')
        } catch (err) {
          expect(err.statusCode).to.equal(HttpStatus.INTERNAL_SERVER_ERROR)
          expect(err.error).to.equal('An unexpected error occurred')
          return
        }

        expect.fail() // Exception should have been thrown due to 500 response code
      })
    })
  })
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:83,代码来源:claimStoreClient.ts

示例3: createOSPlacesClient

 static createOSPlacesClient (): OSPlacesClient {
   return new OSPlacesClient(
     postcodeLookupApiKey,
     request.defaults(requestOptionsOverride)
   )
 }
开发者ID:hmcts,项目名称:cmc-citizen-frontend,代码行数:6,代码来源:clientFactory.ts


注:本文中的client/request.request.defaults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。