2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-11-23 22:33:41 +00:00
|
|
|
// accepts an error and returns error.errors joined with a comma, error.message or a fallback message
|
|
|
|
export default function (error, fallbackMessage = 'An error occurred, please try again') {
|
2022-12-01 01:24:40 +00:00
|
|
|
if (error instanceof Error && error?.errors) {
|
2022-11-23 22:33:41 +00:00
|
|
|
return error.errors.join(', ');
|
|
|
|
}
|
|
|
|
return error?.message || fallbackMessage;
|
|
|
|
}
|