diff --git a/src/lib/download-request.ts b/src/lib/download-request.ts index c3b94fa..43d14a0 100644 --- a/src/lib/download-request.ts +++ b/src/lib/download-request.ts @@ -67,7 +67,7 @@ export class DownloadRequest extends TypedEventTarget< this.#updateState({ status: 'canceled' }) } else if (getErrorCode(error)) { // Specific known error from the server - this.#updateState({ status: 'error', error }) + this.#updateState({ status: 'error', error: jsonError(error) }) } else { // Once the download has started, the sender can only close the // connection to cancel the download, which we only see as an diff --git a/src/lib/map-share.ts b/src/lib/map-share.ts index a795dc9..2178706 100644 --- a/src/lib/map-share.ts +++ b/src/lib/map-share.ts @@ -5,7 +5,7 @@ import { type DownloadStateUpdate, type MapInfo, } from '../types.js' -import { errors } from './errors.js' +import { errors, jsonError } from './errors.js' import { StateUpdateEvent } from './state-update-event.js' import { addTrailingSlash, generateId, getErrorCode } from './utils.js' @@ -155,7 +155,7 @@ export class DownloadResponse extends TypedEventTarget< } else if (getErrorCode(error) === 'ECONNRESET') { this.#updateState({ status: 'aborted' }) } else { - this.#updateState({ status: 'error', error }) + this.#updateState({ status: 'error', error: jsonError(error) }) } }) diff --git a/test/map-shares.test.ts b/test/map-shares.test.ts index 3c81d6a..e218e81 100644 --- a/test/map-shares.test.ts +++ b/test/map-shares.test.ts @@ -361,6 +361,7 @@ describe('Map Shares and Downloads', () => { 'error.code', 'DOWNLOAD_SHARE_NOT_PENDING', ) + expect(events.at(-1)).toHaveProperty('error.message') await completedPromise }, 2000) @@ -385,6 +386,7 @@ describe('Map Shares and Downloads', () => { 'error.code', 'DOWNLOAD_SHARE_NOT_PENDING', ) + expect(events.at(-1)).toHaveProperty('error.message') }) }) @@ -582,6 +584,7 @@ describe('Map Shares and Downloads', () => { 'error.code', 'DOWNLOAD_SHARE_DECLINED', ) + expect(events.at(-1)).toHaveProperty('error.message') }) it('should reject decline on non-pending share', async (t) => { @@ -1590,6 +1593,7 @@ describe('Map Shares and Downloads', () => { .json() expect(downloadStatus.status).toBe('error') expect(downloadStatus).toHaveProperty('error.code', 'DOWNLOAD_ERROR') + expect(downloadStatus).toHaveProperty('error.message') }) it('should clean up temp files on download error', async (t) => {