本文整理汇总了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)
)
}
示例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
})
})
})
示例3: createOSPlacesClient
static createOSPlacesClient (): OSPlacesClient {
return new OSPlacesClient(
postcodeLookupApiKey,
request.defaults(requestOptionsOverride)
)
}