Skip to content

Commit 03183a9

Browse files
shivamhwpclaude
andcommitted
refactor(server): device hub fetch gets a named span; list errors built at the failure
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d221c53 commit 03183a9

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎apps/server/src/device/DeviceHubOperations.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,18 @@ export const makeDeviceHubOperations = (options: {
7575
const { hostId, origin, run } = options;
7676
const httpClient = options.http.pipe(HttpClient.withScope);
7777

78-
const requestFailed = (operation: string) => (cause: unknown) =>
79-
new DeviceOperationError({ operation, reason: "request_failed", cause });
80-
81-
const fetchJson = <A, I>(
78+
const fetchJson = Effect.fn("DeviceHubOperations.fetchJson")(function* <A, I>(
8279
request: HttpClientRequest.HttpClientRequest,
8380
schema: Schema.Codec<A, I>,
84-
) =>
85-
httpClient
81+
) {
82+
return yield* httpClient
8683
.execute(request)
8784
.pipe(
8885
Effect.flatMap(HttpClientResponse.filterStatusOk),
8986
Effect.flatMap(HttpClientResponse.schemaBodyJson(schema)),
9087
Effect.scoped,
9188
);
89+
});
9290

9391
const hubJson = <A, I>(
9492
request: HttpClientRequest.HttpClientRequest,
@@ -98,7 +96,9 @@ export const makeDeviceHubOperations = (options: {
9896
) =>
9997
fetchJson(request, schema).pipe(
10098
Effect.timeout(timeout),
101-
Effect.mapError(requestFailed(operation)),
99+
Effect.mapError(
100+
(cause) => new DeviceOperationError({ operation, reason: "request_failed", cause }),
101+
),
102102
);
103103

104104
const postJson = (path: string, body: Record<string, string>, operation: string) =>
@@ -121,7 +121,9 @@ export const makeDeviceHubOperations = (options: {
121121
HttpClientRequest.get(`${origin}/api/devices`),
122122
HubDeviceList,
123123
).pipe(
124-
Effect.mapError(requestFailed("list")),
124+
Effect.mapError(
125+
(cause) => new DeviceOperationError({ operation: "list", reason: "request_failed", cause }),
126+
),
125127
Effect.timeoutOption(Duration.seconds(LIST_TIMEOUT_SECONDS)),
126128
);
127129
if (Option.isNone(listed)) {

0 commit comments

Comments
 (0)