2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-01-28 00:39:13 +00:00
|
|
|
import { ForbiddenError } from '@ember-data/adapter/error';
|
|
|
|
|
2018-08-15 22:18:38 +00:00
|
|
|
// Returns a single string based on the response the adapter received
|
2021-01-28 00:39:13 +00:00
|
|
|
export default function messageFromAdapterError(error, actionMessage) {
|
|
|
|
if (error instanceof ForbiddenError) {
|
|
|
|
return `Your ACL token does not grant permission to ${actionMessage}.`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error.errors?.length) {
|
2018-08-15 22:18:38 +00:00
|
|
|
return error.errors.mapBy('detail').join('\n\n');
|
|
|
|
}
|
2021-01-28 00:39:13 +00:00
|
|
|
|
|
|
|
return 'Unknown Error';
|
2018-08-15 22:18:38 +00:00
|
|
|
}
|