Files
calendar/packages/lib/http-error.ts
T
54e518efad feat: Allow reschedule when max booker bookings have been reached (#21778)
* feat - Restrict same email to create more than 'n' active bookings at a time

* updated checkbookerbookinglimit function

* type fix

* minor change

* import fix

* minor fixes

* back to null on disable

* back

* type check

* managed edge cases

* chore: name changes

* name changes

* fix

* minor change

* changed name

* use default value for maxactivebookingsperbooker, and some minor changes

* disabling bookerbooking limit for recurring event

* disabling bookerbooking limit for recurring event

* type fix

* ui fix and backend eventtype update check

* Add `maxActiveBookingPerBookerOfferReschedule` to schema

* Create `MaxActiveBookingsPerBookerController` and offer reschedule option

* Add offer reschedule to event type form data

* Pass data through to HttpError

* When checking max bookings, return last booking info if applicable

* removed unused code

* minor changes

* update validation

* chore

* Do not check booking limits if rescheduling

* Add data for reschedule

* Add reschedule specific error code

* On maximum booking error, write to booker store reschedule params

* Add translations for error codes

* Write to error message previous booking time

* minor fix

* Write to error message previous booking time

* Type fixes

* Clean up comment

* Refactor eventType update errors

* Typo fix

* Type fix

* Type fix

* Type fix

* Fix test

* Fix test

* Add migration

* Addressed feedback and missed merges

---------

Co-authored-by: romit <romitgabani@icloud.com>
2025-06-13 23:54:33 +00:00

46 lines
1.4 KiB
TypeScript

export class HttpError<TCode extends number = number> extends Error {
public readonly cause?: Error;
public readonly statusCode: TCode;
public readonly message: string;
public readonly url: string | undefined;
public readonly method: string | undefined;
public readonly data?: Record<string, unknown>;
constructor(opts: {
url?: string;
method?: string;
message?: string;
statusCode: TCode;
cause?: Error;
data?: Record<string, unknown>;
}) {
super(opts.message ?? `HTTP Error ${opts.statusCode} `);
Object.setPrototypeOf(this, HttpError.prototype);
this.name = HttpError.prototype.constructor.name;
this.cause = opts.cause;
this.statusCode = opts.statusCode;
this.url = opts.url;
this.method = opts.method;
this.message = opts.message ?? `HTTP Error ${opts.statusCode}`;
this.data = opts.data;
if (opts.cause instanceof Error && opts.cause.stack) {
this.stack = opts.cause.stack;
}
}
public static fromRequest(request: Request, response: Response, parsedError: Record<string, unknown>) {
return new HttpError({
message: response.statusText,
url: response.url,
method: request.method,
statusCode: response.status,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore the data property is a custom one from ErrorWithCode
data: parsedError.data as Record<string, unknown>,
});
}
}