Skip to content

Commit 6ca25ed

Browse files
committed
fix: convert 404 and 400 http errors to exceptions
1 parent ce655a5 commit 6ca25ed

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,21 @@ const solrPost = config => path => async data => {
4747
)
4848
}
4949

50-
const response = await axios.post(solrUrl, data, {
51-
headers: { "Content-Type": "application/json" }
52-
})
50+
const response = await axios
51+
.post(solrUrl, data, {
52+
headers: { "Content-Type": "application/json" }
53+
})
54+
.catch(reason => {
55+
// converting error response from solr
56+
switch (reason.response.status) {
57+
case 400:
58+
throw Error(reason.response.data.error.msg)
59+
case 404:
60+
throw Error(`${reason.message}: ${reason.response.statusText}`)
61+
default:
62+
throw reason
63+
}
64+
})
5365

5466
return response.data
5567
}

0 commit comments

Comments
 (0)