From 664a21ae179d766df620b5a0e2bf4fff068b6674 Mon Sep 17 00:00:00 2001 From: Allan Zheng Date: Sun, 16 Mar 2025 00:03:22 -0700 Subject: [PATCH 1/2] feat: add error handling page for Storage & Auth --- src/directory/directory.mjs | 6 ++ .../error-handling/index.mdx | 66 ++++++++++++++++++ .../storage/error-handling/index.mdx | 67 +++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx create mode 100644 src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx diff --git a/src/directory/directory.mjs b/src/directory/directory.mjs index 937df52c6dd..06ee1938aca 100644 --- a/src/directory/directory.mjs +++ b/src/directory/directory.mjs @@ -128,6 +128,9 @@ export const directory = { }, { path: 'src/pages/[platform]/build-a-backend/auth/connect-your-frontend/multi-step-sign-in/index.mdx' + }, + { + path: 'src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx' } ] }, @@ -390,6 +393,9 @@ export const directory = { }, { path: 'src/pages/[platform]/build-a-backend/storage/manage-with-amplify-console/index.mdx' + }, + { + path: 'src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx' } ] }, diff --git a/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx b/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx new file mode 100644 index 00000000000..3c835a851ff --- /dev/null +++ b/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx @@ -0,0 +1,66 @@ +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; + +export const meta = { + title: 'Error handling', + description: + 'Handling errors from Amplify Auth', + platforms: [ + 'angular', + 'javascript', + 'nextjs', + 'react', + 'vue', + 'react-native' + ] +}; + +export const getStaticPaths = async () => { + return getCustomStaticPath(meta.platforms); +}; + +export function getStaticProps(context) { + return { + props: { + platform: context.params.platform, + meta + } + }; +} + +The runtime errors thrown by the Amplify Auth APIs may contains additional information to help root-causing the problems. These information are available if the error is an instance of `AuthError`. + +```javascript +import { AuthError, confirmSignUp } from 'aws-amplify/auth'; + +try { + const result = await confirmSignUp({ + username: "hello@mycompany.com", + confirmationCode: "123456" + }); +} catch (error) { + if (error instanceof AuthError) { + console.error('Auth error', error.name); + if (error.metadata) { + console.error('request ID: ', error.metadata.requestId); + } + } + // Further error handling... +} +``` + +`AuthError` may also be thrown by the Storage APIs. + +## All `AuthError` properties + +Property | Type | Required | Description | +| -- | -- | -- | ----------- | +| name | String | Required | Client-side error name or server-side error code. | +| message | String | Required | Error message. | +| stack | String | Optional | Stack trace. | +| recoverySuggestion | String | Optional | Common cause of the error and human-readable recommendation to fix the error.| +| metadata | Object | Optional | Bag of additional error information. | +| metadata.httpStatusCode | number | Optional | The response HTTP status code if the error is caused by erroneous HTTP response. | +| metadata.requestId | String | Optional | The request ID useful to contact AWS Support. | +| metadata.extendedRequestId | String | Optional | The request ID useful to contact AWS Support. | + + diff --git a/src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx b/src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx new file mode 100644 index 00000000000..a9af90d3223 --- /dev/null +++ b/src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx @@ -0,0 +1,67 @@ +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; + +export const meta = { + title: 'Error handling', + description: + 'Handling errors from Amplify Storage', + platforms: [ + 'angular', + 'javascript', + 'nextjs', + 'react', + 'vue', + 'react-native' + ] +}; + +export const getStaticPaths = async () => { + return getCustomStaticPath(meta.platforms); +}; + +export function getStaticProps(context) { + return { + props: { + platform: context.params.platform, + meta + } + }; +} + +The runtime errors thrown by the Amplify Storage APIs may contains additional information to help root-causing the problems. These information are available if the error is an instance of `StorageError`. + +```javascript +import { StorageError, uploadData } from 'aws-amplify/storage'; + +try { + const result = await uploadData({ + path: "album/2024/1.jpg", + data: file, + }).result; + console.log('Succeeded: ', result); +} catch (error) { + if (error instanceof StorageError) { + console.error('Storage error', error.name); + if (error.metadata) { + console.error('request ID: ', error.metadata.requestId); + } + } + // Further error handling... +} +``` + +`AuthError` may also be thrown by the Storage APIs. + +## All `StorageError` properties + +Property | Type | Required | Description | +| -- | -- | -- | ----------- | +| name | String | Required | Client-side error name or server-side error code. | +| message | String | Required | Error message. | +| stack | String | Optional | Stack trace. | +| recoverySuggestion | String | Optional | Common cause of the error and human-readable recommendation to fix the error.| +| metadata | Object | Optional | Bag of additional error information. | +| metadata.httpStatusCode | number | Optional | The response HTTP status code if the error is caused by erroneous HTTP response. | +| metadata.requestId | String | Optional | The request ID useful to [contact AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). | +| metadata.extendedRequestId | String | Optional | The request ID useful to [contact AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). | + + From a3ca9b5fd86a1a006c2a37cbebd02d26a66d0acc Mon Sep 17 00:00:00 2001 From: AllanZhengYP Date: Mon, 17 Mar 2025 14:27:38 -0700 Subject: [PATCH 2/2] chore: address feedbacks Co-authored-by: Chris F <5827964+cshfang@users.noreply.github.com> --- .../auth/connect-your-frontend/error-handling/index.mdx | 6 +++--- .../build-a-backend/storage/error-handling/index.mdx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx b/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx index 3c835a851ff..17cd8b7bc7c 100644 --- a/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx +++ b/src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx @@ -27,7 +27,7 @@ export function getStaticProps(context) { }; } -The runtime errors thrown by the Amplify Auth APIs may contains additional information to help root-causing the problems. These information are available if the error is an instance of `AuthError`. +The runtime errors thrown by the Amplify Auth APIs may contain additional information helpful with identifying root-causes of problems. This information is available if the error is an instance of `AuthError`. ```javascript import { AuthError, confirmSignUp } from 'aws-amplify/auth'; @@ -60,7 +60,7 @@ Property | Type | Required | Description | | recoverySuggestion | String | Optional | Common cause of the error and human-readable recommendation to fix the error.| | metadata | Object | Optional | Bag of additional error information. | | metadata.httpStatusCode | number | Optional | The response HTTP status code if the error is caused by erroneous HTTP response. | -| metadata.requestId | String | Optional | The request ID useful to contact AWS Support. | -| metadata.extendedRequestId | String | Optional | The request ID useful to contact AWS Support. | +| metadata.requestId | String | Optional | The request ID used by AWS when [contacting AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). | +| metadata.extendedRequestId | String | Optional | The extended request ID used by AWS when [contacting AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). | diff --git a/src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx b/src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx index a9af90d3223..c6c9fe6de21 100644 --- a/src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx +++ b/src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx @@ -27,7 +27,7 @@ export function getStaticProps(context) { }; } -The runtime errors thrown by the Amplify Storage APIs may contains additional information to help root-causing the problems. These information are available if the error is an instance of `StorageError`. +The runtime errors thrown by the Amplify Storage APIs may contain additional information helpful with identifying root-causes of problems. This information is available if the error is an instance of `StorageError`. ```javascript import { StorageError, uploadData } from 'aws-amplify/storage'; @@ -61,7 +61,7 @@ Property | Type | Required | Description | | recoverySuggestion | String | Optional | Common cause of the error and human-readable recommendation to fix the error.| | metadata | Object | Optional | Bag of additional error information. | | metadata.httpStatusCode | number | Optional | The response HTTP status code if the error is caused by erroneous HTTP response. | -| metadata.requestId | String | Optional | The request ID useful to [contact AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). | -| metadata.extendedRequestId | String | Optional | The request ID useful to [contact AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). | +| metadata.requestId | String | Optional | The request ID used by AWS when [contacting AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). | +| metadata.extendedRequestId | String | Optional | The extended request ID used by AWS when [contacting AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). |