Refactor task list example application

This commit is contained in:
Steve Kinney
2024-09-18 07:52:42 -06:00
parent e29c63f5cb
commit 2a8720330e
26 changed files with 535 additions and 326 deletions

View File

@@ -0,0 +1,16 @@
/**
*
* @param {unknown} error The error object to check.
* @returns {error is Error}
*/
export const isError = (error) => error instanceof Error;
/**
* Get the error message from an error object or return a default message.
* @param {unknown} error The error object to check.
* @param {string} defaultMessage The default message to return if the error is not an instance of Error.
* @returns {string} The error message or the default message.
*/
export const getErrorMessage = (error, defaultMessage) => {
return isError(error) ? error.message : defaultMessage;
};