{"record":{"id":"1502ba075624e26b","repo":"Kong/insomnia","slug":"code-error-response-status","errorCode":null,"errorMessage":"CODE-${error.response.status}","messagePattern":"CODE-\\$\\{error\\.response\\.status\\}","errorType":"exception","errorClass":"ResponseFailError","httpStatus":null,"severity":"error","filePath":"packages/insomnia-api/src/spaces.ts","lineNumber":72,"sourceCode":"  }\n  // `nextUri` is a path like `/v3/users/me/spaces?page[size]=20&page[after]=...`.\n  // URL needs an absolute base to parse; resolve against the same backend the SDK is configured against.\n  const url = new URL(nextUri, v3Config.getBaseURL());\n  return url.searchParams.get('page[after]') ?? undefined;\n}\n\nasync function readProblemJson(response: Response): Promise<{ title?: string; detail?: string }> {\n  try {\n    return await response.clone().json();\n  } catch {\n    return {};\n  }\n}\n\nasync function mapSdkError(error: unknown): Promise<never> {\n  if (error instanceof ResponseError) {\n    const { title, detail } = await readProblemJson(error.response);\n    throw new ResponseFailError(title || `CODE-${error.response.status}`, detail || error.response.statusText, error.response);\n  }\n  throw error;\n}\n\n/**\n * Lists every space the current user is a member of, paginating through cursors.\n *\n * TODO: switch callers to true pagination — fetch the first page only and expose\n * the cursor so the UI can request more on demand instead of fetching everything\n * up front. Requires UI changes to handle progressive loading.\n */\nexport const getSpaces = async ({ sessionId }: { sessionId: string }): Promise<Space[]> => {\n  const client = buildClient(sessionId);\n  const all: Space[] = [];\n  let pageAfter: string | undefined;\n  try {\n    do {\n      const response: ListCurrentUserSpaces200Response = await client.listCurrentUserSpaces({","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/Kong/insomnia/blob/d9bb2b0142600f21309832daea3317942d285984/packages/insomnia-api/src/spaces.ts#L54-L90","documentation":"Thrown by mapSdkError in the spaces API client when the backend responds with a non-2xx status; it wraps the HTTP status into a CODE-<status> error name so callers can branch on the numeric code (401 unauthenticated, 403 wrong org, 5xx backend failure).","triggerScenarios":"Thrown at packages/insomnia-api/src/spaces.ts:72 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the numeric status: 401/403 means re-authenticate or verify org/space access; 404 means the space id is wrong; 5xx means retry later","Check the ResponseFailError message body for the backend-provided error detail","Verify network/proxy connectivity to the API base URL"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9bb2b0142600f21309832daea3317942d285984","analyzedAt":"2026-08-26T18:04:05.187Z","contentChangedAt":"2026-08-26T18:04:05.187Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}