fix(typedrequest): Add skipHooks flag to TypedRequest to optionally suppress global hooks for internal requests

This commit is contained in:
2025-12-04 22:48:44 +00:00
parent 2a89e88dd1
commit 0d3d5cb562
3 changed files with 37 additions and 21 deletions

View File

@@ -33,6 +33,12 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
public method: string;
/**
* When true, hooks will not be called for this request.
* Use this for internal/logging requests to prevent infinite loops.
*/
public skipHooks: boolean = false;
/**
* @param postEndPointArg
* @param methodArg
@@ -69,15 +75,17 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
}
});
// Hook: outgoing request
callGlobalHook('onOutgoingRequest', {
correlationId: payloadSending.correlation.id,
method: this.method,
direction: 'outgoing',
phase: 'request',
timestamp: requestStartTime,
payload: fireArg,
});
// Hook: outgoing request (skip if this is an internal request)
if (!this.skipHooks) {
callGlobalHook('onOutgoingRequest', {
correlationId: payloadSending.correlation.id,
method: this.method,
direction: 'outgoing',
phase: 'request',
timestamp: requestStartTime,
payload: fireArg,
});
}
let payloadReceiving: plugins.typedRequestInterfaces.ITypedRequest;
payloadReceiving = await this.postTrObject(payloadSending, useCacheArg);
@@ -89,17 +97,19 @@ export class TypedRequest<T extends plugins.typedRequestInterfaces.ITypedRequest
}
});
// Hook: incoming response (for this outgoing request)
callGlobalHook('onIncomingResponse', {
correlationId: payloadSending.correlation.id,
method: this.method,
direction: 'incoming',
phase: 'response',
timestamp: Date.now(),
durationMs: Date.now() - requestStartTime,
payload: payloadReceiving?.response,
error: payloadReceiving?.error?.text,
});
// Hook: incoming response (skip if this is an internal request)
if (!this.skipHooks) {
callGlobalHook('onIncomingResponse', {
correlationId: payloadSending.correlation.id,
method: this.method,
direction: 'incoming',
phase: 'response',
timestamp: Date.now(),
durationMs: Date.now() - requestStartTime,
payload: payloadReceiving?.response,
error: payloadReceiving?.error?.text,
});
}
return payloadReceiving.response;
}