Skip to content

Commit 6f9f728

Browse files
authored
fix: fix missing error.message in download and map share state (#17)
* chore: failing tests for missing error.message in state * fix: fix missing error.message in download and map share state
1 parent 4d31316 commit 6f9f728

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/lib/download-request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class DownloadRequest extends TypedEventTarget<
6767
this.#updateState({ status: 'canceled' })
6868
} else if (getErrorCode(error)) {
6969
// Specific known error from the server
70-
this.#updateState({ status: 'error', error })
70+
this.#updateState({ status: 'error', error: jsonError(error) })
7171
} else {
7272
// Once the download has started, the sender can only close the
7373
// connection to cancel the download, which we only see as an

src/lib/map-share.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type DownloadStateUpdate,
66
type MapInfo,
77
} from '../types.js'
8-
import { errors } from './errors.js'
8+
import { errors, jsonError } from './errors.js'
99
import { StateUpdateEvent } from './state-update-event.js'
1010
import { addTrailingSlash, generateId, getErrorCode } from './utils.js'
1111

@@ -155,7 +155,7 @@ export class DownloadResponse extends TypedEventTarget<
155155
} else if (getErrorCode(error) === 'ECONNRESET') {
156156
this.#updateState({ status: 'aborted' })
157157
} else {
158-
this.#updateState({ status: 'error', error })
158+
this.#updateState({ status: 'error', error: jsonError(error) })
159159
}
160160
})
161161

test/map-shares.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ describe('Map Shares and Downloads', () => {
361361
'error.code',
362362
'DOWNLOAD_SHARE_NOT_PENDING',
363363
)
364+
expect(events.at(-1)).toHaveProperty('error.message')
364365

365366
await completedPromise
366367
}, 2000)
@@ -385,6 +386,7 @@ describe('Map Shares and Downloads', () => {
385386
'error.code',
386387
'DOWNLOAD_SHARE_NOT_PENDING',
387388
)
389+
expect(events.at(-1)).toHaveProperty('error.message')
388390
})
389391
})
390392

@@ -582,6 +584,7 @@ describe('Map Shares and Downloads', () => {
582584
'error.code',
583585
'DOWNLOAD_SHARE_DECLINED',
584586
)
587+
expect(events.at(-1)).toHaveProperty('error.message')
585588
})
586589

587590
it('should reject decline on non-pending share', async (t) => {
@@ -1590,6 +1593,7 @@ describe('Map Shares and Downloads', () => {
15901593
.json<any>()
15911594
expect(downloadStatus.status).toBe('error')
15921595
expect(downloadStatus).toHaveProperty('error.code', 'DOWNLOAD_ERROR')
1596+
expect(downloadStatus).toHaveProperty('error.message')
15931597
})
15941598

15951599
it('should clean up temp files on download error', async (t) => {

0 commit comments

Comments
 (0)