-
Notifications
You must be signed in to change notification settings - Fork 526
fix(server): handle Express 5 req.params type union #729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { getErrorMessage, logError } from '../common.js'; | |
| export function createDeleteHandler(agentService: AgentService) { | ||
| return async (req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| const { sessionId } = req.params; | ||
| const sessionId = req.params.sessionId as string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a type assertion with const sessionId = req.params.sessionId;
if (typeof sessionId !== 'string') {
res.status(400).json({ success: false, error: 'Invalid sessionId parameter' });
return;
} |
||
| const success = await agentService.deleteSession(sessionId); | ||
|
|
||
| if (!success) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { getErrorMessage, logError } from '../common.js'; | |
| export function createUnarchiveHandler(agentService: AgentService) { | ||
| return async (req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| const { sessionId } = req.params; | ||
| const sessionId = req.params.sessionId as string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a type assertion with const sessionId = req.params.sessionId;
if (typeof sessionId !== 'string') {
res.status(400).json({ success: false, error: 'Invalid sessionId parameter' });
return;
} |
||
| const success = await agentService.unarchiveSession(sessionId); | ||
|
|
||
| if (!success) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ import { getErrorMessage, logError } from '../common.js'; | |
| export function createUpdateHandler(agentService: AgentService) { | ||
| return async (req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| const { sessionId } = req.params; | ||
| const sessionId = req.params.sessionId as string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a type assertion with const sessionId = req.params.sessionId;
if (typeof sessionId !== 'string') {
res.status(400).json({ success: false, error: 'Invalid sessionId parameter' });
return;
} |
||
| const { name, tags, model } = req.body as { | ||
| name?: string; | ||
| tags?: string[]; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import { getTerminalService } from '../../../services/terminal-service.js'; | |
| export function createSessionDeleteHandler() { | ||
| return (req: Request, res: Response): void => { | ||
| const terminalService = getTerminalService(); | ||
| const { id } = req.params; | ||
| const id = req.params.id as string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a type assertion with const id = req.params.id;
if (typeof id !== 'string') {
res.status(400).json({ success: false, error: 'Invalid id parameter' });
return;
} |
||
| const killed = terminalService.killSession(id); | ||
|
|
||
| if (!killed) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import { getTerminalService } from '../../../services/terminal-service.js'; | |
| export function createSessionResizeHandler() { | ||
| return (req: Request, res: Response): void => { | ||
| const terminalService = getTerminalService(); | ||
| const { id } = req.params; | ||
| const id = req.params.id as string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a type assertion with const id = req.params.id;
if (typeof id !== 'string') {
res.status(400).json({ success: false, error: 'Invalid id parameter' });
return;
} |
||
| const { cols, rows } = req.body; | ||
|
|
||
| if (!cols || !rows) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a type assertion with
as stringbypasses TypeScript's type safety and can hide runtime errors ifreq.params.sessionIdis not a string (e.g.,undefinedorstring[]). A runtime check is a more robust approach. This ensures the input is validated and invalid requests are handled gracefully with a400 Bad Requestresponse.