Skip to content

Commit 5e89016

Browse files
authored
fix: 204 response for internal docs not found (outline#12067)
1 parent 395da9e commit 5e89016

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

server/routes/api/urls/urls.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ describe("#urls.unfurl", () => {
143143
expect(body.name).toEqual(mentionedUser.name);
144144
});
145145

146+
it("should return 204 when internal document url points to non-existent document", async () => {
147+
const res = await server.post("/api/urls.unfurl", {
148+
body: {
149+
token: user.getJwtToken(),
150+
url: `${env.URL}/doc/non-existent-doc-abc123`,
151+
},
152+
});
153+
expect(res.status).toEqual(204);
154+
});
155+
146156
it("should succeed with status 200 ok when valid document url is supplied", async () => {
147157
const document = await buildDocument({
148158
teamId: user.teamId,

server/routes/api/urls/urls.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ router.post(
164164
const document = await Document.findByPk(previewDocumentId, {
165165
userId: actor.id,
166166
});
167-
if (!document) {
168-
throw NotFoundError("Document does not exist");
167+
if (!document || !can(actor, "read", document)) {
168+
ctx.response.status = 204;
169+
return;
169170
}
170-
authorize(actor, "read", document);
171171

172172
ctx.body = await presentUnfurl({
173173
type: UnfurlResourceType.Document,

0 commit comments

Comments
 (0)