File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -66,8 +66,12 @@ export class AdapterHookable {
66
66
} ;
67
67
}
68
68
} catch ( error ) {
69
- if ( error instanceof Response ) {
70
- return { context, endResponse : error } ;
69
+ const errResponse = ( error as { response : Response } ) . response || error ;
70
+ if ( errResponse instanceof Response ) {
71
+ return {
72
+ context,
73
+ endResponse : errResponse ,
74
+ } ;
71
75
}
72
76
throw error ;
73
77
}
@@ -96,6 +100,8 @@ export type UpgradeRequest =
96
100
headers : Headers ;
97
101
} ;
98
102
103
+ export type UpgradeError = Response | { readonly response : Response } ;
104
+
99
105
export interface Hooks {
100
106
/** Upgrading */
101
107
/**
Original file line number Diff line number Diff line change @@ -58,11 +58,15 @@ export function createDemo<T extends Adapter<any, any>>(
58
58
} ,
59
59
upgrade ( req ) {
60
60
if ( req . url . endsWith ( "?unauthorized" ) ) {
61
- return new Response ( "unauthorized" , {
62
- status : 401 ,
63
- statusText : "Unauthorized" ,
64
- headers : { "x-error" : "unauthorized" } ,
65
- } ) ;
61
+ throw {
62
+ get response ( ) {
63
+ return new Response ( "unauthorized" , {
64
+ status : 401 ,
65
+ statusText : "Unauthorized" ,
66
+ headers : { "x-error" : "unauthorized" } ,
67
+ } ) ;
68
+ } ,
69
+ } ;
66
70
}
67
71
req . context . test = "1" ;
68
72
return {
You can’t perform that action at this time.
0 commit comments