open-nomad/ui/app/utils/message-from-adapter-error.js
Michael Lange 320a63dc68 Improve the message-from-adapter-error util
Automatically detect ACL errors
Provide a generic error message as a fallback
2021-01-28 12:18:52 -08:00

15 lines
442 B
JavaScript

import { ForbiddenError } from '@ember-data/adapter/error';
// Returns a single string based on the response the adapter received
export default function messageFromAdapterError(error, actionMessage) {
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 'Unknown Error';
}