1 |
- {"ast":null,"code":"import _asyncToGenerator from \"F:/workspace/202226701027/huinongbao-app/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nfunction getErrorStackTrace(e) {\n if (typeof e !== \"object\" || e == null) return undefined;\n if (!(\"stack\" in e) || typeof e.stack !== \"string\") return undefined;\n let stack = e.stack;\n const prevLine = `${e}`;\n if (stack.startsWith(prevLine)) {\n stack = stack.slice(prevLine.length);\n }\n if (stack.startsWith(\"\\n\")) {\n stack = stack.slice(1);\n }\n return stack;\n}\nexport function printErrorStackTrace(e) {\n const stack = getErrorStackTrace(e);\n if (stack == null) return;\n console.error(stack);\n}\n/**\n * LangSmithConflictError\n *\n * Represents an error that occurs when there's a conflict during an operation,\n * typically corresponding to HTTP 409 status code responses.\n *\n * This error is thrown when an attempt to create or modify a resource conflicts\n * with the current state of the resource on the server. Common scenarios include:\n * - Attempting to create a resource that already exists\n * - Trying to update a resource that has been modified by another process\n * - Violating a uniqueness constraint in the data\n *\n * @extends Error\n *\n * @example\n * try {\n * await createProject(\"existingProject\");\n * } catch (error) {\n * if (error instanceof ConflictError) {\n * console.log(\"A conflict occurred:\", error.message);\n * // Handle the conflict, e.g., by suggesting a different project name\n * } else {\n * // Handle other types of errors\n * }\n * }\n *\n * @property {string} name - Always set to 'ConflictError' for easy identification\n * @property {string} message - Detailed error message including server response\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409\n */\nexport class LangSmithConflictError extends Error {\n constructor(message) {\n super(message);\n this.name = \"LangSmithConflictError\";\n }\n}\n/**\n * Throws an appropriate error based on the response status and body.\n *\n * @param response - The fetch Response object\n * @param context - Additional context to include in the error message (e.g., operation being performed)\n * @throws {LangSmithConflictError} When the response status is 409\n * @throws {Error} For all other non-ok responses\n */\nexport function raiseForStatus(_x, _x2, _x3) {\n return _raiseForStatus.apply(this, arguments);\n}\nfunction _raiseForStatus() {\n _raiseForStatus = _asyncToGenerator(function* (response, context, consume) {\n // consume the response body to release the connection\n // https://undici.nodejs.org/#/?id=garbage-collection\n let errorBody;\n if (response.ok) {\n if (consume) {\n errorBody = yield response.text();\n }\n return;\n }\n errorBody = yield response.text();\n const fullMessage = `Failed to ${context}. Received status [${response.status}]: ${response.statusText}. Server response: ${errorBody}`;\n if (response.status === 409) {\n throw new LangSmithConflictError(fullMessage);\n }\n throw new Error(fullMessage);\n });\n return _raiseForStatus.apply(this, arguments);\n}","map":{"version":3,"names":["getErrorStackTrace","e","undefined","stack","prevLine","startsWith","slice","length","printErrorStackTrace","console","error","LangSmithConflictError","Error","constructor","message","name","raiseForStatus","_x","_x2","_x3","_raiseForStatus","apply","arguments","_asyncToGenerator","response","context","consume","errorBody","ok","text","fullMessage","status","statusText"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/langsmith/dist/utils/error.js"],"sourcesContent":["function getErrorStackTrace(e) {\n if (typeof e !== \"object\" || e == null)\n return undefined;\n if (!(\"stack\" in e) || typeof e.stack !== \"string\")\n return undefined;\n let stack = e.stack;\n const prevLine = `${e}`;\n if (stack.startsWith(prevLine)) {\n stack = stack.slice(prevLine.length);\n }\n if (stack.startsWith(\"\\n\")) {\n stack = stack.slice(1);\n }\n return stack;\n}\nexport function printErrorStackTrace(e) {\n const stack = getErrorStackTrace(e);\n if (stack == null)\n return;\n console.error(stack);\n}\n/**\n * LangSmithConflictError\n *\n * Represents an error that occurs when there's a conflict during an operation,\n * typically corresponding to HTTP 409 status code responses.\n *\n * This error is thrown when an attempt to create or modify a resource conflicts\n * with the current state of the resource on the server. Common scenarios include:\n * - Attempting to create a resource that already exists\n * - Trying to update a resource that has been modified by another process\n * - Violating a uniqueness constraint in the data\n *\n * @extends Error\n *\n * @example\n * try {\n * await createProject(\"existingProject\");\n * } catch (error) {\n * if (error instanceof ConflictError) {\n * console.log(\"A conflict occurred:\", error.message);\n * // Handle the conflict, e.g., by suggesting a different project name\n * } else {\n * // Handle other types of errors\n * }\n * }\n *\n * @property {string} name - Always set to 'ConflictError' for easy identification\n * @property {string} message - Detailed error message including server response\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409\n */\nexport class LangSmithConflictError extends Error {\n constructor(message) {\n super(message);\n this.name = \"LangSmithConflictError\";\n }\n}\n/**\n * Throws an appropriate error based on the response status and body.\n *\n * @param response - The fetch Response object\n * @param context - Additional context to include in the error message (e.g., operation being performed)\n * @throws {LangSmithConflictError} When the response status is 409\n * @throws {Error} For all other non-ok responses\n */\nexport async function raiseForStatus(response, context, consume) {\n // consume the response body to release the connection\n // https://undici.nodejs.org/#/?id=garbage-collection\n let errorBody;\n if (response.ok) {\n if (consume) {\n errorBody = await response.text();\n }\n return;\n }\n errorBody = await response.text();\n const fullMessage = `Failed to ${context}. Received status [${response.status}]: ${response.statusText}. Server response: ${errorBody}`;\n if (response.status === 409) {\n throw new LangSmithConflictError(fullMessage);\n }\n throw new Error(fullMessage);\n}\n"],"mappings":";AAAA,SAASA,kBAAkBA,CAACC,CAAC,EAAE;EAC3B,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAIA,CAAC,IAAI,IAAI,EAClC,OAAOC,SAAS;EACpB,IAAI,EAAE,OAAO,IAAID,CAAC,CAAC,IAAI,OAAOA,CAAC,CAACE,KAAK,KAAK,QAAQ,EAC9C,OAAOD,SAAS;EACpB,IAAIC,KAAK,GAAGF,CAAC,CAACE,KAAK;EACnB,MAAMC,QAAQ,GAAG,GAAGH,CAAC,EAAE;EACvB,IAAIE,KAAK,CAACE,UAAU,CAACD,QAAQ,CAAC,EAAE;IAC5BD,KAAK,GAAGA,KAAK,CAACG,KAAK,CAACF,QAAQ,CAACG,MAAM,CAAC;EACxC;EACA,IAAIJ,KAAK,CAACE,UAAU,CAAC,IAAI,CAAC,EAAE;IACxBF,KAAK,GAAGA,KAAK,CAACG,KAAK,CAAC,CAAC,CAAC;EAC1B;EACA,OAAOH,KAAK;AAChB;AACA,OAAO,SAASK,oBAAoBA,CAACP,CAAC,EAAE;EACpC,MAAME,KAAK,GAAGH,kBAAkB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"module","externalDependencies":[]}
|