(connection: ExecutorServerConnection, target: ServerTarget = {})
| 1069 | // --------------------------------------------------------------------------- |
| 1070 | |
| 1071 | const makeApiClient = (connection: ExecutorServerConnection, target: ServerTarget = {}) => |
| 1072 | Effect.gen(function* () { |
| 1073 | const headers = yield* resolveExecutorServerRequestHeaders(connection, process.env).pipe( |
| 1074 | Effect.mapError(toError), |
| 1075 | ); |
| 1076 | return yield* HttpApiClient.make(ExecutorApi, { |
| 1077 | baseUrl: connection.apiBaseUrl, |
| 1078 | ...(Object.keys(headers).length > 0 |
| 1079 | ? { |
| 1080 | transformClient: HttpClient.mapRequest((request) => |
| 1081 | HttpClientRequest.setHeaders(request, headers), |
| 1082 | ), |
| 1083 | } |
| 1084 | : {}), |
| 1085 | // A 401 on an endpoint that doesn't model it is a sign-in problem: rewrite |
| 1086 | // the transport-level error into the login hint. Without this the client |
| 1087 | // fails decoding the unexpected status and prints the opaque |
| 1088 | // `Decode error (401 GET .../api/tools)`. Declared 401s (typed API errors) |
| 1089 | // decode before this catch and pass through untouched. |
| 1090 | transformResponse: (effect) => |
| 1091 | Effect.catchIf( |
| 1092 | effect, |
| 1093 | (cause) => HttpClientError.isHttpClientError(cause) && cause.response?.status === 401, |
| 1094 | () => |
| 1095 | Effect.fail( |
| 1096 | new Error(describeUnauthorizedCliServer({ connection, cliPrefix, target })), |
| 1097 | ), |
| 1098 | ), |
| 1099 | }); |
| 1100 | }).pipe(Effect.provide(FetchHttpClient.layer)); |
| 1101 | |
| 1102 | // --------------------------------------------------------------------------- |
| 1103 | // Foreground session |
no test coverage detected