errors.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { Schema } from "effect"
  2. export class InvalidRequestError extends Schema.TaggedErrorClass<InvalidRequestError>()(
  3. "InvalidRequestError",
  4. {
  5. message: Schema.String,
  6. kind: Schema.optional(Schema.String),
  7. field: Schema.optional(Schema.String),
  8. },
  9. { httpApiStatus: 400 },
  10. ) {}
  11. export class UnauthorizedError extends Schema.TaggedErrorClass<UnauthorizedError>()(
  12. "UnauthorizedError",
  13. { message: Schema.String },
  14. { httpApiStatus: 401 },
  15. ) {}
  16. export class ConflictError extends Schema.TaggedErrorClass<ConflictError>()(
  17. "ConflictError",
  18. {
  19. message: Schema.String,
  20. resource: Schema.optional(Schema.String),
  21. },
  22. { httpApiStatus: 409 },
  23. ) {}
  24. export class ServiceUnavailableError extends Schema.TaggedErrorClass<ServiceUnavailableError>()(
  25. "ServiceUnavailableError",
  26. {
  27. message: Schema.String,
  28. service: Schema.optional(Schema.String),
  29. },
  30. { httpApiStatus: 503 },
  31. ) {}
  32. export class UnknownError extends Schema.TaggedErrorClass<UnknownError>()(
  33. "UnknownError",
  34. {
  35. message: Schema.String,
  36. ref: Schema.optional(Schema.String),
  37. },
  38. { httpApiStatus: 500 },
  39. ) {}
  40. export class ProviderNotFoundError extends Schema.TaggedErrorClass<ProviderNotFoundError>()(
  41. "ProviderNotFoundError",
  42. {
  43. providerID: Schema.String,
  44. message: Schema.String,
  45. },
  46. { httpApiStatus: 404 },
  47. ) {}
  48. export class SessionNotFoundError extends Schema.TaggedErrorClass<SessionNotFoundError>()(
  49. "SessionNotFoundError",
  50. {
  51. sessionID: Schema.String,
  52. message: Schema.String,
  53. },
  54. { httpApiStatus: 404 },
  55. ) {}
  56. export class MessageNotFoundError extends Schema.TaggedErrorClass<MessageNotFoundError>()(
  57. "MessageNotFoundError",
  58. {
  59. sessionID: Schema.String,
  60. messageID: Schema.String,
  61. message: Schema.String,
  62. },
  63. { httpApiStatus: 404 },
  64. ) {}
  65. export class InvalidCursorError extends Schema.TaggedErrorClass<InvalidCursorError>()(
  66. "InvalidCursorError",
  67. { message: Schema.String },
  68. { httpApiStatus: 400 },
  69. ) {}
  70. export class PermissionNotFoundError extends Schema.TaggedErrorClass<PermissionNotFoundError>()(
  71. "PermissionNotFoundError",
  72. {
  73. requestID: Schema.String,
  74. message: Schema.String,
  75. },
  76. { httpApiStatus: 404 },
  77. ) {}
  78. export class QuestionNotFoundError extends Schema.TaggedErrorClass<QuestionNotFoundError>()(
  79. "QuestionNotFoundError",
  80. {
  81. requestID: Schema.String,
  82. message: Schema.String,
  83. },
  84. { httpApiStatus: 404 },
  85. ) {}
  86. export class ForbiddenError extends Schema.TaggedErrorClass<ForbiddenError>()(
  87. "ForbiddenError",
  88. { message: Schema.String },
  89. { httpApiStatus: 403 },
  90. ) {}
  91. export class PtyNotFoundError extends Schema.TaggedErrorClass<PtyNotFoundError>()(
  92. "PtyNotFoundError",
  93. {
  94. ptyID: Schema.String,
  95. message: Schema.String,
  96. },
  97. { httpApiStatus: 404 },
  98. ) {}