new HabiticaApiError()
Returned when the API request returns a HTTP status between 400 and 500
- Source:
Example
Use the error objects on the Habitica package to write an error handler
var Habitica = require('habitica')
var api = new Habitica({
// setup client
})
api.get('/user').then(() => {
// will never get here
}).catch((err) => {
if (err instanceof Habitica.ApiError) {
// likely a validation error from
// the API request
console.log(err.message)
} else if (err instanceof Habitica.UnknownConnectionError) {
// either the Habitica API is down
// or there is no internet connection
console.log(err.originalError)
} else {
// there is something wrong with your integration
// such as a syntax error or other problem
console.log(err)
}
})
Members
(static) this.message
A translated error message you can provide for your user
- Source:
(static) this.status
The status code of the HTTP request. Will be a number >= 400
and <= 500
- Source:
(static) this.type
A type coresponding to the status code. For instance, an error with a status of 404
will be type NotFound
- Source: