SIAF / src /lib /promise.ts
GUI-STUDIO
Add HF mini-apps and sync workflows
0f454b6
Raw
History Blame Contribute Delete
492 Bytes
// Generic promise error handler
function F_catch_promise<T>(arg0: {
promise: Promise<T>;
}): Promise<[undefined, T] | [Error, undefined]> {
const { promise } = arg0;
let final_promise = promise;
const promise_resolver = final_promise
.then((data) => {
return [undefined, data] as [undefined, T];
})
.catch((error) => {
return [error, undefined] as [Error, undefined];
});
return promise_resolver;
}
export const NS_promise = {
F_catch_promise,
};