fix(mattermost): use client.request in patchMattermostPost and deleteMattermostPost

Both functions called the global fetch directly, bypassing the fetchImpl
stored in the client closure. This silently ignored any custom fetch
implementation passed to createMattermostClient (test mocks, proxy-aware
fetchers, SSRF guards).

Switch both to client.request<void>() which uses fetchImpl, auto-injects
the Authorization header, handles Content-Type for JSON bodies, and
propagates errors consistently with every other client function.

uploadMattermostFile retains its direct fetch call (multipart/form-data
conflicts with request's automatic Content-Type injection).

Addresses Greptile review: 'New functions bypass client.request,
ignoring custom fetchImpl'.
This commit is contained in:
teconomix 2026-03-14 06:13:08 +00:00
parent ec10de7361
commit ee6d984950

View File

@ -542,20 +542,10 @@ export async function patchMattermostPost(
client: MattermostClient,
params: { postId: string; message: string },
): Promise<void> {
const res = await fetch(`${client.apiBaseUrl}/posts/${params.postId}/patch`, {
await client.request<void>(`/posts/${params.postId}/patch`, {
method: "PUT",
headers: {
Authorization: `Bearer ${client.token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ message: params.message }),
});
if (!res.ok) {
const detail = await readMattermostError(res);
throw new Error(
`Mattermost patch post ${res.status} ${res.statusText}: ${detail || "unknown error"}`,
);
}
}
/**
@ -565,16 +555,7 @@ export async function deleteMattermostPost(
client: MattermostClient,
postId: string,
): Promise<void> {
const res = await fetch(`${client.apiBaseUrl}/posts/${postId}`, {
await client.request<void>(`/posts/${postId}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${client.token}`,
},
});
if (!res.ok) {
const detail = await readMattermostError(res);
throw new Error(
`Mattermost delete post ${res.status} ${res.statusText}: ${detail || "unknown error"}`,
);
}
}