@etsoo/shared
Version:
TypeScript shared utilities and functions
27 lines (26 loc) • 644 B
JavaScript
/**
* Action result
*/
export class ActionResult {
/**
* Create a result from error
* @returns Action result interface
*/
static create(error) {
// If the error has status / statusCode
const status = "status" in error
? error.status
: "statusCode" in error
? error.statusCode
: undefined;
// Result
const result = {
status: typeof status === "number" ? status : undefined,
ok: false,
type: error.name,
title: error.message
};
// Return
return result;
}
}