Skip to content
This repository was archived by the owner on May 6, 2023. It is now read-only.

Commit 13df85e

Browse files
committed
add new types for cors errors and handling; add class for handling buxt specific errors; add class for handling cors related errors
1 parent 4cf7c84 commit 13df85e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

index.d.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,27 @@ export declare class BuxtServer {
5757

5858
private registerRoutes(req: BuxtRequest, res: BuxtResponse, mappedRoute: Route): Promise<void>;
5959
private handleRequest(): Promise<Response> | Response;
60+
private validateCors(req: Request): string;
61+
private appendCorsHeaders(response: BuxtResponse, origin: string): void;
62+
private handleCorsOptionsRequest(req: Request): BuxtResponse;
63+
private handleCorsHeaderRequest(req: Request, res: BuxtResponse): void;
6064

6165
listen(): Promise<void>;
6266
stop(): void;
6367
}
6468

69+
export declare class BuxtError extends Error {
70+
errorHeaders: { [key: string]: string };
71+
72+
constructor(message: string);
73+
74+
attachHeaders(response: Response): void;
75+
}
76+
77+
export declare class CorsError extends BuxtError {
78+
constructor(message: string);
79+
}
80+
6581
export declare type RoutePath = {
6682
FullPath: string,
6783
AbsolutePath: string
@@ -77,7 +93,6 @@ export declare type RouteParameters = {
7793
[key: string]: string
7894
}
7995

80-
8196
export type BuxtConfig = {
8297
port: number,
8398
routeRoot: string,

src/BuxtError.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default class BuxtError extends Error {
2+
errorHeaders: { [key: string]: string };
3+
4+
constructor(message: string) {
5+
super(message);
6+
}
7+
8+
attachHeaders(response: Response): void {
9+
response.headers.append("Buxt-Rejection-Cause", this.name);
10+
response.headers.append("Buxt-Rejection-Reason", this.message);
11+
}
12+
}

src/errors/CorsError.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import BuxtError from "../BuxtError";
2+
3+
export default class CorsError extends BuxtError {
4+
constructor(message: string) {
5+
super(message);
6+
this.name = "CorsError";
7+
this.message = message;
8+
}
9+
}

0 commit comments

Comments
 (0)