mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-31 04:38:11 +00:00
fix(stacks): return a handled response when saving env to a stack with no env file (#1393)
PUT /api/stacks/:stackName/env resolved no env path when a stack had a compose file but no .env on disk. It then wrote to an undefined path, which threw and surfaced as an opaque 500. Guard the missing-env case and return a clean 404 so direct API callers get an actionable response instead of a crash. The editor still only edits an existing env file, so behavior in the UI is unchanged.
This commit is contained in:
@@ -644,6 +644,14 @@ stacksRouter.put('/:stackName/env', async (req: Request, res: Response) => {
|
||||
}
|
||||
}
|
||||
|
||||
// No env file resolved: the stack has no .env yet and the editor only edits
|
||||
// an existing env file. GET treats this same case as an empty 200; PUT cannot,
|
||||
// since there is no resolved path to write. Reply with a clean, handled response
|
||||
// instead of writing to an undefined path, which would otherwise surface as an opaque 500.
|
||||
if (!envPath) {
|
||||
return res.status(404).json({ error: 'No env file exists for this stack' });
|
||||
}
|
||||
|
||||
const fsService = FileSystemService.getInstance(req.nodeId);
|
||||
const expectedMtimeMs = parseIfMatchMtime(req.header('if-match'));
|
||||
const result = await fsService.writeFileIfUnchanged(envPath, content, expectedMtimeMs);
|
||||
|
||||
Reference in New Issue
Block a user