Improve the message-from-adapter-error util
Automatically detect ACL errors Provide a generic error message as a fallback
This commit is contained in:
parent
94094d4f18
commit
320a63dc68
|
@ -1,6 +1,14 @@
|
||||||
|
import { ForbiddenError } from '@ember-data/adapter/error';
|
||||||
|
|
||||||
// Returns a single string based on the response the adapter received
|
// Returns a single string based on the response the adapter received
|
||||||
export default function messageFromAdapterError(error) {
|
export default function messageFromAdapterError(error, actionMessage) {
|
||||||
if (error.errors) {
|
if (error instanceof ForbiddenError) {
|
||||||
|
return `Your ACL token does not grant permission to ${actionMessage}.`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.errors?.length) {
|
||||||
return error.errors.mapBy('detail').join('\n\n');
|
return error.errors.mapBy('detail').join('\n\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 'Unknown Error';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue