Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit eb9bbb7

Browse files
authored
Merge pull request #51 from netlify/handle-422-with-addons
Handle 422 response from all addons endpoints
2 parents 9b94de1 + 5f96dba commit eb9bbb7

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/addons.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function createAddon(settings, netlifyApiToken) {
2121
const data = await response.json()
2222

2323
if (response.status === 422) {
24-
throw new Error(`Error ${JSON.stringify(data)}`)
24+
throw new Error(data.error)
2525
}
2626

2727
return data
@@ -40,7 +40,7 @@ async function getAddons(siteId, netlifyApiToken) {
4040
const data = await response.json()
4141

4242
if (response.status === 422) {
43-
throw new Error(`Error ${JSON.stringify(data)}`)
43+
throw new Error(data.error)
4444
}
4545

4646
return data
@@ -58,6 +58,11 @@ async function deleteAddon(settings, netlifyApiToken) {
5858
}
5959
})
6060

61+
if (response.status === 422) {
62+
const data = await response.json()
63+
throw new Error(data.error)
64+
}
65+
6166
return response
6267
}
6368

@@ -77,6 +82,12 @@ async function updateAddon(settings, netlifyApiToken) {
7782
}),
7883
})
7984

85+
const data = await response.json()
86+
87+
if (response.status === 422) {
88+
throw new Error(data.error)
89+
}
90+
8091
return response
8192
}
8293

0 commit comments

Comments
 (0)