Introduce a generic error handler for application/vnd.error+json, that publishes the error as an error object on the response:
Something along these lines:
factory('errorInterceptor', function ($q, HalError) {
return {
'responseError': function (response) {
if (response.headers('Content-Type') === 'application/vnd.error+json') {
response.error = new HalError(response.data);
} else {
response.error = {
message: response.statusText,
status: response.status
};
}
return $q.reject(response);
}
};
})
Als introduce mechanism for client of the library to configure their own error handlers by media type.