Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions src/lib/map-share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export class MapShare extends TypedEventTarget<
decline(
reason: Extract<MapShareStateUpdate, { status: 'declined' }>['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}'`,
Expand Down
8 changes: 4 additions & 4 deletions test/map-shares.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) => {
Expand Down Expand Up @@ -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
Expand All @@ -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')
})
})
})
Expand Down