fix(sdk): requestPlugin skips cross-service 'no matching handler' errors with fallback timer
This commit is contained in:
parent
89d871e5d6
commit
c5f43da97b
|
|
@ -238,16 +238,35 @@ export class CoreService {
|
||||||
const result = await new Promise<T | null>((resolve) => {
|
const result = await new Promise<T | null>((resolve) => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
this.logger.warn(`[requestPlugin] Timeout for ${routingKey}`);
|
this.logger.warn(`[requestPlugin] Timeout for ${routingKey}`);
|
||||||
|
if (errorFallback) clearTimeout(errorFallback);
|
||||||
resolve(null);
|
resolve(null);
|
||||||
}, timeoutMs);
|
}, timeoutMs);
|
||||||
|
|
||||||
|
let errorFallback: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
ch.consume(replyQueue.queue, (rmqMsg) => {
|
ch.consume(replyQueue.queue, (rmqMsg) => {
|
||||||
if (rmqMsg && rmqMsg.properties.correlationId === correlationId) {
|
if (rmqMsg && rmqMsg.properties.correlationId === correlationId) {
|
||||||
clearTimeout(timer);
|
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(rmqMsg.content.toString());
|
const parsed = JSON.parse(rmqMsg.content.toString());
|
||||||
resolve(parsed.response ?? parsed);
|
const response = parsed.response ?? parsed;
|
||||||
|
|
||||||
|
// Skip "no matching handler" errors from other services
|
||||||
|
// and wait for the correct response (up to timeoutMs - 1s)
|
||||||
|
if (response && response.err) {
|
||||||
|
if (!errorFallback) {
|
||||||
|
errorFallback = setTimeout(() => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
resolve(response);
|
||||||
|
}, Math.min(timeoutMs - 1000, 15000));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorFallback) clearTimeout(errorFallback);
|
||||||
|
clearTimeout(timer);
|
||||||
|
resolve(response);
|
||||||
} catch {
|
} catch {
|
||||||
|
clearTimeout(timer);
|
||||||
resolve(null);
|
resolve(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue