@@ -13,6 +13,32 @@ export class ComputeGatewayClient {
1313 req : TemplateCreateRequest ,
1414 options ?: { signal ?: AbortSignal }
1515 ) : Promise < { accepted : boolean } > {
16+ const response = await this . #fetch( req , options ?. signal ) ;
17+
18+ if ( ! response . ok ) {
19+ const errorBody = await response . text ( ) . catch ( ( ) => "unknown error" ) ;
20+ throw new Error ( `Gateway template creation failed (${ response . status } ): ${ errorBody } ` ) ;
21+ }
22+
23+ return { accepted : response . status === 202 } ;
24+ }
25+
26+ /**
27+ * Fire-and-forget template creation. Sends the request but does not
28+ * await the response, so no HTTP connection is held open.
29+ */
30+ createTemplateBackground ( req : TemplateCreateRequest ) : void {
31+ this . #fetch( req ) . then (
32+ ( response ) => {
33+ if ( ! response . ok ) {
34+ response . text ( ) . catch ( ( ) => { } ) ;
35+ }
36+ } ,
37+ ( ) => { } // swallow network errors
38+ ) ;
39+ }
40+
41+ #fetch( req : TemplateCreateRequest , signal ?: AbortSignal ) : Promise < Response > {
1642 const url = `${ this . opts . gatewayUrl } /api/templates` ;
1743
1844 const headers : Record < string , string > = {
@@ -22,20 +48,11 @@ export class ComputeGatewayClient {
2248 headers [ "Authorization" ] = `Bearer ${ this . opts . authToken } ` ;
2349 }
2450
25- const signal = options ?. signal ?? AbortSignal . timeout ( this . opts . timeoutMs ) ;
26-
27- const response = await fetch ( url , {
51+ return fetch ( url , {
2852 method : "POST" ,
2953 headers,
3054 body : JSON . stringify ( req ) ,
31- signal,
55+ signal : signal ?? AbortSignal . timeout ( this . opts . timeoutMs ) ,
3256 } ) ;
33-
34- if ( ! response . ok ) {
35- const errorBody = await response . text ( ) . catch ( ( ) => "unknown error" ) ;
36- throw new Error ( `Gateway template creation failed (${ response . status } ): ${ errorBody } ` ) ;
37- }
38-
39- return { accepted : response . status === 202 } ;
4057 }
4158}
0 commit comments