diff --git a/src/lib/errors.ts b/src/lib/errors.ts index a231558..7b646ae 100644 --- a/src/lib/errors.ts +++ b/src/lib/errors.ts @@ -71,6 +71,11 @@ const errorsList = [ message: 'Cannot cancel: share is not pending or downloading', status: 409, }, + { + code: 'MAP_SHARE_CANCELED', + message: 'Map share has been canceled by the sender', + status: 409, + }, { code: 'DECLINE_SHARE_NOT_PENDING', message: 'Cannot decline: share is not pending', diff --git a/src/lib/map-share.ts b/src/lib/map-share.ts index 2178706..ba64627 100644 --- a/src/lib/map-share.ts +++ b/src/lib/map-share.ts @@ -78,6 +78,9 @@ export class MapShare extends TypedEventTarget< decline( reason: Extract['reason'], ) { + if (this.#state.status === 'canceled') { + throw new errors.MAP_SHARE_CANCELED() + } if (this.#state.status !== 'pending') { throw new errors.DECLINE_SHARE_NOT_PENDING( `Cannot decline: share status is '${this.#state.status}'`, diff --git a/test/map-shares.test.ts b/test/map-shares.test.ts index 8e49745..bc37579 100644 --- a/test/map-shares.test.ts +++ b/test/map-shares.test.ts @@ -589,7 +589,7 @@ describe('Map Shares and Downloads', () => { expect(events.at(-1)).toHaveProperty('error.message') }) - it('should reject decline on non-pending share', async (t) => { + it('should return MAP_SHARE_CANCELED when declining a canceled share', async (t) => { const { createShare, sender, receiver } = await startServers(t) const share = await createShare().json() @@ -609,7 +609,7 @@ describe('Map Shares and Downloads', () => { ) expect(declineResponse.status).toBe(409) const declineError = await declineResponse.json() - expect(declineError).toHaveProperty('code', 'DECLINE_SHARE_NOT_PENDING') + expect(declineError).toHaveProperty('code', 'MAP_SHARE_CANCELED') }) it('should return 404 when declining non-existent share', async (t) => { @@ -1271,7 +1271,7 @@ describe('Map Shares and Downloads', () => { const { createShare, sender, receiver } = await startServers(t) const share = await createShare().json() - // First, cancel the share so decline will fail with DECLINE_SHARE_NOT_PENDING + // First, cancel the share so decline will fail with MAP_SHARE_CANCELED await sender.post(`mapShares/${share.shareId}/cancel`) // Now try to decline remotely - should get the error passed through @@ -1288,7 +1288,7 @@ describe('Map Shares and Downloads', () => { expect(response.status).toBe(409) const error = await response.json() - expect(error).toHaveProperty('code', 'DECLINE_SHARE_NOT_PENDING') + expect(error).toHaveProperty('code', 'MAP_SHARE_CANCELED') }) }) })