(connection: ExecutorServerConnection, target: ServerTarget = {})
| 1055 | // --------------------------------------------------------------------------- |
| 1056 | |
| 1057 | const makeApiClient = (connection: ExecutorServerConnection, target: ServerTarget = {}) => { |
| 1058 | const authorization = getExecutorServerAuthorizationHeader(connection); |
| 1059 | return HttpApiClient.make(ExecutorApi, { |
| 1060 | baseUrl: connection.apiBaseUrl, |
| 1061 | ...(authorization |
| 1062 | ? { |
| 1063 | transformClient: HttpClient.mapRequest((request) => |
| 1064 | HttpClientRequest.setHeader(request, "authorization", authorization), |
| 1065 | ), |
| 1066 | } |
| 1067 | : {}), |
| 1068 | // A 401 on an endpoint that doesn't model it is a sign-in problem: rewrite |
| 1069 | // the transport-level error into the login hint. Without this the client |
| 1070 | // fails decoding the unexpected status and prints the opaque |
| 1071 | // `Decode error (401 GET .../api/tools)`. Declared 401s (typed API errors) |
| 1072 | // decode before this catch and pass through untouched. |
| 1073 | transformResponse: (effect) => |
| 1074 | Effect.catchIf( |
| 1075 | effect, |
| 1076 | (cause) => HttpClientError.isHttpClientError(cause) && cause.response?.status === 401, |
| 1077 | () => |
| 1078 | Effect.fail(new Error(describeUnauthorizedCliServer({ connection, cliPrefix, target }))), |
| 1079 | ), |
| 1080 | }).pipe(Effect.provide(FetchHttpClient.layer)); |
| 1081 | }; |
| 1082 | |
| 1083 | // --------------------------------------------------------------------------- |
| 1084 | // Foreground session |
no test coverage detected