Skip to content

fix: API response of metadata handler on invalid app ID is different from the file get handler #10108

@coderabbitai

Description

@coderabbitai

Summary

The metadataHandler in src/Routers/FilesRouter.js returns HTTP 200 with an empty JSON object ({}) when the app ID is invalid (config is missing), while getHandler returns HTTP 403 with "Invalid application ID." for the same condition. This inconsistency can mask configuration errors for callers of the metadata endpoint.

Expected behavior

metadataHandler should return HTTP 403 with an appropriate error message when the config is missing, consistent with getHandler:

       const config = Config.get(req.params.appId);
       if (!config) {
-        res.status(200);
-        res.json({});
+        const error = createSanitizedHttpError(403, 'Invalid application ID.', config);
+        res.status(error.status);
+        res.json({ error: error.message });
         return;
       }

The existing test does not crash on file metadata request with invalid app ID will need to be updated to assert the new 403 response.

Context

Identified during review of #10106 (comment: #10106 (comment)). The inconsistency predates that PR and is intentionally out of scope for it.

Requested by @mtrezza.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions