|
7 | 7 | type EnvironmentId, |
8 | 8 | type ServerProvider, |
9 | 9 | } from "@t3tools/contracts"; |
10 | | -import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; |
| 10 | +import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; |
11 | 11 | import { AsyncResult } from "effect/reactivity"; |
12 | 12 | import { useEffect, useRef, useState } from "react"; |
13 | 13 | import { View } from "react-native"; |
@@ -96,16 +96,15 @@ function EnvironmentDetail({ environmentId }: { readonly environmentId: Environm |
96 | 96 | setPending(label); |
97 | 97 | setError(null); |
98 | 98 | setNotice(null); |
99 | | - await action() |
100 | | - .catch((cause: unknown) => { |
101 | | - setError( |
102 | | - cause instanceof Error ? cause.message : "The action could not be completed. Try again.", |
103 | | - ); |
104 | | - }) |
105 | | - .finally(() => { |
106 | | - pendingRef.current = false; |
107 | | - setPending(null); |
108 | | - }); |
| 99 | + const result = await settlePromise(action); |
| 100 | + pendingRef.current = false; |
| 101 | + setPending(null); |
| 102 | + if (AsyncResult.isFailure(result)) { |
| 103 | + const cause = squashAtomCommandFailure(result); |
| 104 | + setError( |
| 105 | + cause instanceof Error ? cause.message : "The action could not be completed. Try again.", |
| 106 | + ); |
| 107 | + } |
109 | 108 | } |
110 | 109 |
|
111 | 110 | function requestServerUpdate() { |
@@ -269,14 +268,14 @@ function EnvironmentDetail({ environmentId }: { readonly environmentId: Environm |
269 | 268 | checkController.current = controller; |
270 | 269 | const timeout = setTimeout(() => controller.abort(), 20_000); |
271 | 270 | const fromVersion = config.environment.serverVersion; |
272 | | - const targetVersion = await findEnvironmentUpdate( |
273 | | - fromVersion, |
274 | | - controller.signal, |
275 | | - ).finally(() => { |
276 | | - clearTimeout(timeout); |
277 | | - checkController.current = null; |
278 | | - }); |
279 | | - setRelease({ fromVersion, targetVersion }); |
| 271 | + const result = await settlePromise(() => |
| 272 | + findEnvironmentUpdate(fromVersion, controller.signal), |
| 273 | + ); |
| 274 | + clearTimeout(timeout); |
| 275 | + checkController.current = null; |
| 276 | + // `run` owns the error message, so a failed lookup rethrows to it. |
| 277 | + if (AsyncResult.isFailure(result)) throw squashAtomCommandFailure(result); |
| 278 | + setRelease({ fromVersion, targetVersion: result.value }); |
280 | 279 | }); |
281 | 280 | }} |
282 | 281 | /> |
|
0 commit comments