Skip to content

Commit 0312aeb

Browse files
committed
Fix for error not propagating (but only if there's no response)
1 parent d7260ca commit 0312aeb

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

apps/webapp/app/routes/resources.metric.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,28 @@ export function MetricWidget({
191191
body: JSON.stringify(propsRef.current),
192192
signal: controller.signal,
193193
})
194-
.then((res) => res.json() as Promise<MetricWidgetActionResponse>)
194+
.then(async (res) => {
195+
try {
196+
return (await res.json()) as MetricWidgetActionResponse;
197+
} catch {
198+
throw new Error(`Request failed (${res.status})`);
199+
}
200+
})
195201
.then((data) => {
196202
if (!controller.signal.aborted) {
197203
setResponse(data);
198204
setIsLoading(false);
199205
}
200206
})
201207
.catch((err) => {
202-
// Ignore aborted requests
203208
if (err instanceof DOMException && err.name === "AbortError") return;
204209
if (!controller.signal.aborted) {
210+
// Only surface the error if there's no existing successful data to preserve
211+
setResponse((prev) =>
212+
prev?.success
213+
? prev
214+
: { success: false, error: err.message || "Network error" }
215+
);
205216
setIsLoading(false);
206217
}
207218
});

0 commit comments

Comments
 (0)