open-nomad/ui/app/utils/message-from-adapter-error.js
2023-04-10 15:36:59 +00:00

20 lines
520 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
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';
}