How catch 'bad request' from Strapi ?
Closed this issue · 0 comments
theo-stocchetti commented
Hi,
Thanks for this library, i have a question, how i can catch a bad request message from Strapi ?
// with axios
this.$axios.post('users/me', { data })
.then((response) => {
console.log(response)
})
.catch((error) => {
console.log(error.response.data.message.shift().messages.shift().id)
// console : Auth.form.error.email.format
})
// with nuxt-strapi
let send
try {
send = await this.$strapi.request('POST', 'users/me', { data })
console.log(send.data)
} catch (error) {
console.log(error)
/* console :
Error: [object Object]
at Strapi._callee$ (strapi.js?b045:26)
at tryCatch (runtime.js?96cf:45)
at Generator.invoke [as _invoke] (runtime.js?96cf:271)
at Generator.prototype.<computed> [as throw] (runtime.js?96cf:97)
at asyncGeneratorStep (asyncToGenerator.js?1da1:3)
at _throw (asyncToGenerator.js?1da1:29)
*/
console.log(send)
// undefined
It work with this fix on request() from strapi.js, but i don't know if is the good way
} catch (error) {
if (error.response) {
return error.response
//throw new Error(error.response)
} else {
throw error
}
}