Skip to content

Commit

Permalink
Improve the message-from-adapter-error util
Browse files Browse the repository at this point in the history
Automatically detect ACL errors
Provide a generic error message as a fallback
  • Loading branch information
DingoEatingFuzz committed Jan 28, 2021
1 parent 5bbe53f commit d7793b3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ui/app/utils/message-from-adapter-error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { ForbiddenError } from '@ember-data/adapter/error';

// 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) {
return error.errors.mapBy('detail').join('\n\n');
}

if (error instanceof ForbiddenError) {
return `Your ACL token does not grant permission to ${actionMessage}.`;
}

return 'Unknown Error';
}

0 comments on commit d7793b3

Please sign in to comment.