* refactor: replace TRPCError with ErrorWithCode in packages/features This refactor moves error handling from throwing TRPCError directly in packages/features to throwing ErrorWithCode instead. The conversion to TRPCError now happens at the TRPC layer. Changes: - Add generic ErrorCode values (Unauthorized, Forbidden, NotFound, BadRequest, InternalServerError) to errorCodes.ts - Update getServerErrorFromUnknown to map new ErrorCodes to proper HTTP status codes - Create toTRPCError helper in packages/trpc/server/lib - Create errorMappingMiddleware in packages/trpc/server/middlewares - Migrate TRPCError throws in packages/features to ErrorWithCode: - teamService.ts - getEventTypeById.ts - eventTypeRepository.ts - OrganizationPermissionService.ts - OrganizationPaymentService.ts - sso.ts - handleCreatePhoneCall.ts - userCanCreateTeamGroupMapping.ts This improves separation of concerns by making packages/features transport-agnostic, allowing the same feature code to be reused from tRPC, API routes, workers, etc. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix: remove isTrpcCall parameter and fix lint warning - Remove isTrpcCall parameter from get.handler.ts call since the feature layer no longer needs to know about tRPC - Fix unsafe optional chaining lint warning in getEventTypesByViewer.ts by precomputing usersSource variable - Complete migration of getEventTypesByViewer.ts to ErrorWithCode Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * revert * add eslint rule * add comment * fix: add isTrpcCall back to getEventTypeById interface The user reverted the removal of isTrpcCall parameter from the handler, so we need to add it back to the interface to fix the type error. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * test: update teamService tests to expect ErrorWithCode instead of TRPCError Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * refactor * wip * feat: integrate errorMappingMiddleware into base TRPC procedure Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * connect middlewares * revert * revert * refactor * rename * fix: handle ErrorWithCode in teams server-page error handling The error handling was checking for TRPCError, but teamService now throws ErrorWithCode. This caused the 'This invitation is not for your account' error message to not be displayed when a wrong user tries to use an invitation link. Co-Authored-By: benny@cal.com <sldisek783@gmail.com> * fix * fix * fix --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
42 lines
2.2 KiB
TypeScript
42 lines
2.2 KiB
TypeScript
export enum ErrorCode {
|
|
// Generic HTTP error codes for transport-agnostic error handling
|
|
Unauthorized = "unauthorized_error",
|
|
Forbidden = "forbidden_error",
|
|
NotFound = "not_found_error",
|
|
BadRequest = "bad_request_error",
|
|
InternalServerError = "internal_server_error",
|
|
|
|
// Domain-specific error codes
|
|
PaymentCreationFailure = "payment_not_created_error",
|
|
NoAvailableUsersFound = "no_available_users_found_error",
|
|
ChargeCardFailure = "couldnt_charge_card_error",
|
|
RequestBodyWithouEnd = "request_body_end_time_internal_error",
|
|
AlreadySignedUpForBooking = "already_signed_up_for_this_booking_error",
|
|
FixedHostsUnavailableForBooking = "fixed_hosts_unavailable_for_booking",
|
|
RoundRobinHostsUnavailableForBooking = "round_robin_host_unavailable_for_booking",
|
|
EventTypeNotFound = "event_type_not_found_error",
|
|
BookingNotFound = "booking_not_found_error",
|
|
BookingSeatsFull = "booking_seats_full_error",
|
|
MissingPaymentCredential = "missing_payment_credential_error",
|
|
MissingPaymentAppId = "missing_payment_app_id_error",
|
|
NotEnoughAvailableSeats = "not_enough_available_seats_error",
|
|
AvailabilityNotFoundInSchedule = "availability_not_found_in_schedule_error",
|
|
CancelledBookingsCannotBeRescheduled = "cancelled_bookings_cannot_be_rescheduled",
|
|
UnableToSubscribeToThePlatform = "unable_to_subscribe_to_the_platform",
|
|
UpdatingOauthClientError = "updating_oauth_client_error",
|
|
CreatingOauthClientError = "creating_oauth_client_error",
|
|
BookingTimeOutOfBounds = "booking_time_out_of_bounds_error",
|
|
BookingConflict = "booking_conflict_error",
|
|
BookerLimitExceeded = "booker_limit_exceeded_error",
|
|
BookerLimitExceededReschedule = "booker_limit_exceeded_error_reschedule",
|
|
BookingNotAllowedByRestrictionSchedule = "booking_not_allowed_by_restriction_schedule_error",
|
|
RestrictionScheduleNotFound = "restriction_schedule_not_found_error",
|
|
EventTypeNoHosts = "event_type_no_hosts",
|
|
RequestBodyInvalid = "request_body_invalid_error",
|
|
PrivateLinkExpired = "private_link_expired",
|
|
BookerEmailBlocked = "booker_email_blocked",
|
|
BookerEmailRequiresLogin = "booker_email_requires_login",
|
|
InvalidVerificationCode = "invalid_verification_code",
|
|
UnableToValidateVerificationCode = "unable_to_validate_verification_code",
|
|
}
|