Skip to content

Commit 13c04b1

Browse files
committed
Fix type safety errors and test failures in data packet routes
Remove unsafe 'as any' type casts and send full error objects instead of extracting message strings. This fixes ESLint warnings and aligns with test expectations.
1 parent c22f56d commit 13c04b1

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

routes/dataPackets.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ export function exists (request: Request, response: Response) {
1818
.then(resultId => response.status(200)
1919
.send(resultId))
2020
.catch((resultId: unknown) => {
21-
const message = (resultId as any)?.message ?? String(resultId)
22-
return response.status(404).send(message)
21+
return response.status(404).send(resultId)
2322
}))
2423
.catch((error: unknown) => {
25-
const message = (error as any)?.message ?? String(error)
26-
return response.status(400).send(message)
24+
return response.status(400).send(error)
2725
})
2826
}
2927

@@ -34,28 +32,24 @@ export function get (request: Request, response: Response) {
3432
.then(packet => response.status(200)
3533
.json(packet))
3634
.catch((resultId: unknown) => {
37-
const message = (resultId as any)?.message ?? String(resultId)
38-
return response.status(404).send(message)
35+
return response.status(404).send(resultId)
3936
}))
4037
.catch((error: unknown) => {
41-
const message = (error as any)?.message ?? String(error)
42-
return response.status(400).send(message)
38+
return response.status(400).send(error)
4339
})
4440
}
4541

4642
export function put (request: Request, response: Response) {
4743
const id = Array.isArray(request.params.id) ? request.params.id[0] : request.params.id
4844
return dpStorage.isSaneId(id)
49-
.then(() => dpStorage.put({id, data: request.body})
45+
.then(() => dpStorage.put({id, data: request.body as Record<string, unknown>})
5046
.then(() => response.status(200)
5147
.send(id))
5248
.catch((resultId: unknown) => {
53-
const message = (resultId as any)?.message ?? String(resultId)
54-
return response.status(404).send(message)
49+
return response.status(404).send(resultId)
5550
}))
5651
.catch((error: unknown) => {
57-
const message = (error as any)?.message ?? String(error)
58-
return response.status(400).send(message)
52+
return response.status(400).send(error)
5953
})
6054
}
6155

@@ -66,12 +60,10 @@ export function delete_ (request: Request, response: Response) {
6660
.then(() => response.status(204)
6761
.send())
6862
.catch((resultId: unknown) => {
69-
const message = (resultId as any)?.message ?? String(resultId)
70-
return response.status(404).send(message)
63+
return response.status(404).send(resultId)
7164
}))
7265
.catch((error: unknown) => {
73-
const message = (error as any)?.message ?? String(error)
74-
return response.status(400).send(message)
66+
return response.status(400).send(error)
7567
})
7668
}
7769

0 commit comments

Comments
 (0)