ghunti-devour-client
Version:
A lightweight, framework agnostic, flexible JSON API client
24 lines (21 loc) • 452 B
JavaScript
function buildErrors (serverErrors) {
if (!serverErrors) {
console.log('Unidentified error')
return
} else {
let errors = {}
serverErrors.errors.forEach((error) => {
errors[errorKey(error.source)] = error.title
})
return errors
}
}
function errorKey (source) {
return source.pointer.split('/').pop()
}
module.exports = {
name: 'errors',
error: function (payload) {
return buildErrors(payload.data)
}
}