Skip to content

Commit 664a21a

Browse files
committed
feat: add error handling page for Storage & Auth
1 parent 8e6a250 commit 664a21a

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

src/directory/directory.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ export const directory = {
128128
},
129129
{
130130
path: 'src/pages/[platform]/build-a-backend/auth/connect-your-frontend/multi-step-sign-in/index.mdx'
131+
},
132+
{
133+
path: 'src/pages/[platform]/build-a-backend/auth/connect-your-frontend/error-handling/index.mdx'
131134
}
132135
]
133136
},
@@ -390,6 +393,9 @@ export const directory = {
390393
},
391394
{
392395
path: 'src/pages/[platform]/build-a-backend/storage/manage-with-amplify-console/index.mdx'
396+
},
397+
{
398+
path: 'src/pages/[platform]/build-a-backend/storage/error-handling/index.mdx'
393399
}
394400
]
395401
},
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Error handling',
5+
description:
6+
'Handling errors from Amplify Auth',
7+
platforms: [
8+
'angular',
9+
'javascript',
10+
'nextjs',
11+
'react',
12+
'vue',
13+
'react-native'
14+
]
15+
};
16+
17+
export const getStaticPaths = async () => {
18+
return getCustomStaticPath(meta.platforms);
19+
};
20+
21+
export function getStaticProps(context) {
22+
return {
23+
props: {
24+
platform: context.params.platform,
25+
meta
26+
}
27+
};
28+
}
29+
30+
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`.
31+
32+
```javascript
33+
import { AuthError, confirmSignUp } from 'aws-amplify/auth';
34+
35+
try {
36+
const result = await confirmSignUp({
37+
username: "[email protected]",
38+
confirmationCode: "123456"
39+
});
40+
} catch (error) {
41+
if (error instanceof AuthError) {
42+
console.error('Auth error', error.name);
43+
if (error.metadata) {
44+
console.error('request ID: ', error.metadata.requestId);
45+
}
46+
}
47+
// Further error handling...
48+
}
49+
```
50+
51+
`AuthError` may also be thrown by the Storage APIs.
52+
53+
## All `AuthError` properties
54+
55+
Property | Type | Required | Description |
56+
| -- | -- | -- | ----------- |
57+
| name | String | Required | Client-side error name or server-side error code. |
58+
| message | String | Required | Error message. |
59+
| stack | String | Optional | Stack trace. |
60+
| recoverySuggestion | String | Optional | Common cause of the error and human-readable recommendation to fix the error.|
61+
| metadata | Object | Optional | Bag of additional error information. |
62+
| metadata.httpStatusCode | number | Optional | The response HTTP status code if the error is caused by erroneous HTTP response. |
63+
| metadata.requestId | String | Optional | The request ID useful to contact AWS Support. |
64+
| metadata.extendedRequestId | String | Optional | The request ID useful to contact AWS Support. |
65+
66+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { getCustomStaticPath } from '@/utils/getCustomStaticPath';
2+
3+
export const meta = {
4+
title: 'Error handling',
5+
description:
6+
'Handling errors from Amplify Storage',
7+
platforms: [
8+
'angular',
9+
'javascript',
10+
'nextjs',
11+
'react',
12+
'vue',
13+
'react-native'
14+
]
15+
};
16+
17+
export const getStaticPaths = async () => {
18+
return getCustomStaticPath(meta.platforms);
19+
};
20+
21+
export function getStaticProps(context) {
22+
return {
23+
props: {
24+
platform: context.params.platform,
25+
meta
26+
}
27+
};
28+
}
29+
30+
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`.
31+
32+
```javascript
33+
import { StorageError, uploadData } from 'aws-amplify/storage';
34+
35+
try {
36+
const result = await uploadData({
37+
path: "album/2024/1.jpg",
38+
data: file,
39+
}).result;
40+
console.log('Succeeded: ', result);
41+
} catch (error) {
42+
if (error instanceof StorageError) {
43+
console.error('Storage error', error.name);
44+
if (error.metadata) {
45+
console.error('request ID: ', error.metadata.requestId);
46+
}
47+
}
48+
// Further error handling...
49+
}
50+
```
51+
52+
`AuthError` may also be thrown by the Storage APIs.
53+
54+
## All `StorageError` properties
55+
56+
Property | Type | Required | Description |
57+
| -- | -- | -- | ----------- |
58+
| name | String | Required | Client-side error name or server-side error code. |
59+
| message | String | Required | Error message. |
60+
| stack | String | Optional | Stack trace. |
61+
| recoverySuggestion | String | Optional | Common cause of the error and human-readable recommendation to fix the error.|
62+
| metadata | Object | Optional | Bag of additional error information. |
63+
| metadata.httpStatusCode | number | Optional | The response HTTP status code if the error is caused by erroneous HTTP response. |
64+
| metadata.requestId | String | Optional | The request ID useful to [contact AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). |
65+
| metadata.extendedRequestId | String | Optional | The request ID useful to [contact AWS Support](https://docs.aws.amazon.com/AmazonS3/latest/API/get-request-ids.html). |
66+
67+

0 commit comments

Comments
 (0)