Workspaces refactor #86

Merged
norm merged 189 commits from refactor/workspaces into main 2022-08-28 14:46:45 +00:00
Showing only changes of commit 1bd75619dd - Show all commits

View file

@ -1,5 +1,7 @@
import { Endpoints } from './endpoints'; import { Endpoints } from './endpoints';
const MK_API_ERROR = Symbol();
export type APIError = { export type APIError = {
id: string; id: string;
code: string; code: string;
@ -8,6 +10,10 @@ export type APIError = {
info: Record<string, any>; info: Record<string, any>;
}; };
export function isAPIError(reason: any): reason is APIError {
return reason[MK_API_ERROR] === true;
}
export function request<E extends keyof Endpoints>( export function request<E extends keyof Endpoints>(
origin: string, origin: string,
endpoint: E, endpoint: E,
@ -32,7 +38,10 @@ export function request<E extends keyof Endpoints>(
} else if (res.status === 204) { } else if (res.status === 204) {
resolve(null); resolve(null);
} else { } else {
reject(body.error); reject({
[MK_API_ERROR]: true,
...body.error
});
} }
}).catch(reject); }).catch(reject);
}); });