1
1
/**
2
2
* Creates a HTTP redirect response with the specified URL.
3
- *
3
+ *
4
4
* @param url - The URL to redirect to.
5
5
* @param headers - Optional `Headers` object to include additional headers. Defaults to an empty `Headers` object.
6
6
* @param body - Optional body to include in the response. Defaults to `null`.
7
7
* @returns A `Response` object with a `302` status and the `Location` header set to the specified URL.
8
8
*/
9
9
export function createRedirectResponse (
10
- url : string ,
11
- headers : Headers = new Headers ( ) ,
12
- body : unknown = null
10
+ url : string ,
11
+ headers : Headers = new Headers ( ) ,
12
+ body : unknown = null ,
13
13
) : Response {
14
14
headers . set ( "location" , url ) ;
15
15
@@ -21,7 +21,7 @@ export function createRedirectResponse(
21
21
22
22
/**
23
23
* Creates a HTTP error response with a 500 status code.
24
- *
24
+ *
25
25
* @param error - The error message to include in the response body.
26
26
* @returns A `Response` object with a `500` status and an error message in the JSON body.
27
27
*/
@@ -31,7 +31,7 @@ export function createErrorResponse(error: string): Response {
31
31
32
32
/**
33
33
* Creates a HTTP unauthorized response with a 401 status code.
34
- *
34
+ *
35
35
* @param error - Optional error message to include in the response body. Defaults to "Unauthorized".
36
36
* @returns A `Response` object with a `401` status and an error message in the JSON body.
37
37
*/
@@ -41,13 +41,13 @@ export function createUnathorizedResponse(error = "Unauthorized"): Response {
41
41
42
42
/**
43
43
* Creates a HTTP success response with a `200` status code.
44
- *
45
- * @param body - A record containing key-value pairs to include in the response body.
44
+ *
45
+ * @param body - A record containing key-value pairs to include in the response body.
46
46
* The values can be strings, numbers, or booleans.
47
47
* @returns A `Response` object with a `200` status, `success: true` in the body, and any additional data provided.
48
48
*/
49
49
export function createSuccessResponse (
50
- body : Record < string , string | number | boolean >
50
+ body : Record < string , string | number | boolean > ,
51
51
) : Response {
52
52
return Response . json ( { success : true , ...body } ) ;
53
53
}
0 commit comments