2023-03-15 12:00:52 -04:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-10 21:14:03 -04:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-15 12:00:52 -04:00
|
|
|
*/
|
|
|
|
|
|
2022-11-23 17:33:41 -05: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') {
|
2024-01-11 13:55:26 -05:00
|
|
|
if (error instanceof Error && error?.errors && typeof error.errors[0] === 'string') {
|
2022-11-23 17:33:41 -05:00
|
|
|
return error.errors.join(', ');
|
|
|
|
|
}
|
|
|
|
|
return error?.message || fallbackMessage;
|
|
|
|
|
}
|