1
0
mirror of https://github.com/vercel/commerce.git synced 2025-07-27 20:21:22 +00:00
Files
.github
.vscode
app
components
fonts
lib
shopify
constants.ts
type-guards.ts
utils.ts
.env.example
.eslintrc.js
.gitignore
.nvmrc
.prettierignore
README.md
license.md
next.config.js
package.json
pnpm-lock.yaml
postcss.config.js
prettier.config.js
tailwind.config.js
tsconfig.json
commerce/lib/type-guards.ts
Michael Novotny 528ad9b8ce Adds better error messages and environment variable fault tolerance ()
* Adds better error messages and environment variable fault tolerance

* No hidden undefined
2023-08-11 20:19:49 -05:00

28 lines
726 B
TypeScript

export interface ShopifyErrorLike {
status: number;
message: Error;
cause?: Error;
}
export const isObject = (object: unknown): object is Record<string, unknown> => {
return typeof object === 'object' && object !== null && !Array.isArray(object);
};
export const isShopifyError = (error: unknown): error is ShopifyErrorLike => {
if (!isObject(error)) return false;
if (error instanceof Error) return true;
return findError(error);
};
function findError<T extends object>(error: T): boolean {
if (Object.prototype.toString.call(error) === '[object Error]') {
return true;
}
const prototype = Object.getPrototypeOf(error) as T | null;
return prototype === null ? false : findError(prototype);
}