error.d.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export declare function printErrorStackTrace(e: unknown): void;
  2. /**
  3. * LangSmithConflictError
  4. *
  5. * Represents an error that occurs when there's a conflict during an operation,
  6. * typically corresponding to HTTP 409 status code responses.
  7. *
  8. * This error is thrown when an attempt to create or modify a resource conflicts
  9. * with the current state of the resource on the server. Common scenarios include:
  10. * - Attempting to create a resource that already exists
  11. * - Trying to update a resource that has been modified by another process
  12. * - Violating a uniqueness constraint in the data
  13. *
  14. * @extends Error
  15. *
  16. * @example
  17. * try {
  18. * await createProject("existingProject");
  19. * } catch (error) {
  20. * if (error instanceof ConflictError) {
  21. * console.log("A conflict occurred:", error.message);
  22. * // Handle the conflict, e.g., by suggesting a different project name
  23. * } else {
  24. * // Handle other types of errors
  25. * }
  26. * }
  27. *
  28. * @property {string} name - Always set to 'ConflictError' for easy identification
  29. * @property {string} message - Detailed error message including server response
  30. *
  31. * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409
  32. */
  33. export declare class LangSmithConflictError extends Error {
  34. status: number;
  35. constructor(message: string);
  36. }
  37. /**
  38. * Throws an appropriate error based on the response status and body.
  39. *
  40. * @param response - The fetch Response object
  41. * @param context - Additional context to include in the error message (e.g., operation being performed)
  42. * @throws {LangSmithConflictError} When the response status is 409
  43. * @throws {Error} For all other non-ok responses
  44. */
  45. export declare function raiseForStatus(response: Response, context: string, consume?: boolean): Promise<void>;