Amplify Libraries

FeedbackFeedbackEditEditDiscord LogoChat with usWe'd love your feedback

Storage

Cancel requests

You may cancel any put, get, or copy requests made by the Storage API by keeping a reference to the promise returned.

const promise = Storage.get('key'); Storage.cancel(promise, "my message for cancellation"); try { await promise; } catch (error) { console.error(error); // We can confirm the error is thrown by the cancellation here if (Storage.isCancelError(error)) { console.error(error.message); // "my message for cancellation" } }

const promise = Storage.get('key'); Storage.cancel(promise, "my message for cancellation"); try { await promise; } catch (error) { console.error(error); // We can confirm the error is thrown by the cancellation here if (Storage.isCancelError(error)) { console.error(error.message); // "my message for cancellation" } }

Caveat

Since the cancellation requires original reference of the promise, you need to make sure the return value of the request has not been modified. Usually async function wraps the promise being returned into another promise. For example

async function makeRequest() { return Storage.get('key'); } const promise = makeRequest(); // This won't cancel the request Storage.cancel(promise);

async function makeRequest() { return Storage.get('key'); } const promise = makeRequest(); // This won't cancel the request Storage.cancel(promise);
Previous Page
previous

Remove files

next

File access levels

Next Page
Discord Logo
Amplify open source, documentation and community are supported by Amazon Web Services © 2021, Amazon Web Services, Inc. and its affiliates. All rights reserved. View the site terms and privacy policy.
    Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.