Skip to content

Commit 8b07619

Browse files
authored
fix: fix v6 block not showing up for cancel example (aws-amplify#6747)
1 parent 7bcac3e commit 8b07619

File tree

1 file changed

+20
-20
lines changed
  • src/pages/[platform]/build-a-backend/restapi/restapi-v5-to-v6-migration-guide

1 file changed

+20
-20
lines changed

src/pages/[platform]/build-a-backend/restapi/restapi-v5-to-v6-migration-guide/index.mdx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -460,53 +460,53 @@ For v6 REST APIs, all API's use the same underlying input/output types, although
460460
The process for cancelling a request has changed in v6. In v5 you send in the promise as input to the API.cancel API. In v6, cancel is a function returned with the result of an API(REST) operation. To cancel an operation, you will call `operation.cancel()`.
461461

462462
<BlockSwitcher>
463-
<Block name="V5">
463+
<Block name="V6">
464464
```js
465-
import { API } from 'aws-amplify'
465+
import { get, isCancelError } from 'aws-amplify/api'
466466

467-
const promise = API.get(
468-
apiName,
469-
path,
467+
const operation = get({
468+
apiName,
469+
path,
470470
options
471-
);
471+
});
472472

473-
promise.then(result => {
473+
operation.response.then(result => {
474474
// GET operation completed successfully
475475
}).catch(error => {
476476
// If the error is because the request was cancelled you can confirm here.
477-
if(API.isCancel(error)) {
477+
if(isCancelError(error)) {
478478
// 'my message for cancellation'
479479
console.log(error.message);
480480
}
481-
});
481+
})
482482

483483
// To cancel the above request
484-
API.cancel(promise, 'my message for cancellation');
484+
operation.cancel('my message for cancellation');
485485
```
486486

487487
</Block>
488-
<Block>
488+
<Block name="V5">
489489
```js
490-
import { get, isCancelError } from 'aws-amplify/api'
490+
import { API } from 'aws-amplify'
491491

492-
const operation = get({
493-
apiName,
494-
path,
492+
const promise = API.get(
493+
apiName,
494+
path,
495495
options
496-
});
496+
);
497497

498-
operation.response.then(result => {
498+
promise.then(result => {
499499
// GET operation completed successfully
500500
}).catch(error => {
501501
// If the error is because the request was cancelled you can confirm here.
502-
if(isCancelError(error)) {
502+
if(API.isCancel(error)) {
503503
// 'my message for cancellation'
504504
console.log(error.message);
505505
}
506-
})
506+
});
507507

508508
// To cancel the above request
509-
operation.cancel('my message for cancellation');
509+
API.cancel(promise, 'my message for cancellation');
510510
```
511511

512512
</Block>

0 commit comments

Comments
 (0)