diff --git a/src/core/batch.ts b/src/core/batch.ts index 56af25a7..68e6facb 100644 --- a/src/core/batch.ts +++ b/src/core/batch.ts @@ -117,7 +117,7 @@ class BatchService extends Service { } const data = [] as { stackId: string, transactionId: string, object: Stack }[]; - const errors = [] as { name: string, message: string }[]; + const errors = [] as { name: string, message: string, error: Error }[]; if (options.progressHook) { const onProgress = options.progressHook @@ -150,8 +150,8 @@ class BatchService extends Service { if (options.onStackCreated) { await options.onStackCreated(stackResponse.object); } - } catch (e) { - errors.push({ name: item.name, message: e.toString() }) + } catch (error) { + errors.push({ name: item.name, message: error.toString(), error }) }; })) if (options.cancelHook?.signal.aborted) { diff --git a/src/core/profile.ts b/src/core/profile.ts index 6caf57a4..cc52a609 100644 --- a/src/core/profile.ts +++ b/src/core/profile.ts @@ -34,7 +34,7 @@ class ProfileService extends Service { }) public async update(name: string, avatar: ArrayBuffer): Promise<{ transactions: { id: string, transactionId: string }[], - errors: { id: string, error: any }[] + errors: { id: string, error: Error }[] }> { // update profile const user = await this.api.getUser(); diff --git a/src/core/service.ts b/src/core/service.ts index 50e6d428..7d0d1290 100644 --- a/src/core/service.ts +++ b/src/core/service.ts @@ -368,13 +368,13 @@ class Service { } protected async handleListErrors(originalItems: Array, promises: Array>) - : Promise<{ items: Array, errors: Array<{ id: string, error: string }> }> { + : Promise<{ items: Array, errors: Array<{ id: string, error: Error }> }> { const results = await Promise.all(promises.map(p => p.catch(e => e))); const items = results.filter(result => !(result instanceof Error)); const errors = results .map((result, index) => ({ result, index })) .filter((mapped) => mapped.result instanceof Error) - .map((filtered) => ({ id: (originalItems[filtered.index]).id, error: filtered.result.message })); + .map((filtered) => ({ id: (originalItems[filtered.index]).id, error: filtered.result })); return { items, errors }; } diff --git a/src/types/batch-response.ts b/src/types/batch-response.ts index fb6ce0a0..ea7bd4fb 100644 --- a/src/types/batch-response.ts +++ b/src/types/batch-response.ts @@ -2,11 +2,11 @@ import { Stack } from "./node" export interface BatchStackCreateResponse { data: Array<{ stackId: string, transactionId: string, object: Stack }> - errors: Array<{ name: string, message: string }> + errors: Array<{ name: string, message: string, error: Error }> cancelled: number } export interface BatchMembershipInviteResponse { data: Array<{ membershipId: string, transactionId: string }> - errors: Array<{ email: string, message: string }> + errors: Array<{ email: string, message: string, error: Error }> } diff --git a/src/types/paginated.ts b/src/types/paginated.ts index 406bb29c..5419895c 100644 --- a/src/types/paginated.ts +++ b/src/types/paginated.ts @@ -5,7 +5,7 @@ const PAGINATION_HEADER = 'next-page' export type Paginated = { items: Array nextToken: string - errors?: Array<{ id: string, error: string }> + errors?: Array<{ id: string, error: Error }> } export const isPaginated = (response: AxiosResponse) => {