|
1 | 1 | import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip"; |
2 | 2 | import { scopeThreadRef } from "@t3tools/client-runtime/environment"; |
| 3 | +import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; |
3 | 4 | import type { EnvironmentId, PullRequestRef, ScopedThreadRef, ThreadId } from "@t3tools/contracts"; |
4 | 5 | import { CheckIcon, MessageSquareIcon } from "lucide-react"; |
5 | 6 | import { useState } from "react"; |
@@ -75,17 +76,18 @@ function EnabledPullRequestThreadLinks({ |
75 | 76 | const changeLink = async (threadId: ThreadId, remove: boolean) => { |
76 | 77 | if (parsed === null || pending) return; |
77 | 78 | setPending(true); |
78 | | - try { |
79 | | - await linking.changeLink(scopeThreadRef(environmentId, threadId), url, !remove); |
80 | | - } catch (error) { |
| 79 | + const result = await settlePromise(() => |
| 80 | + linking.changeLink(scopeThreadRef(environmentId, threadId), url, !remove), |
| 81 | + ); |
| 82 | + setPending(false); |
| 83 | + if (result._tag === "Failure") { |
| 84 | + const error = squashAtomCommandFailure(result); |
81 | 85 | toastManager.add({ |
82 | 86 | type: "error", |
83 | 87 | title: remove ? "Could not unlink the pull request" : "Could not link the pull request", |
84 | 88 | description: error instanceof Error ? error.message : String(error), |
85 | 89 | }); |
86 | 90 | return; |
87 | | - } finally { |
88 | | - setPending(false); |
89 | 91 | } |
90 | 92 | if (linking.mode === "multiple") { |
91 | 93 | appAtomRegistry.refresh( |
|
0 commit comments