@fluwa-tool/sdk 1.0.27 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,7 +19,6 @@ export declare class XMLHttpRequestInterceptor implements IXMLHttpRequestInterce
|
|
|
19
19
|
private originalSend;
|
|
20
20
|
private originalSetRequestHeader;
|
|
21
21
|
private isInstalled;
|
|
22
|
-
private isIntercepting;
|
|
23
22
|
constructor(logger: ILogger, requestLogger: IRequestLogger, mockResolver: IMockResolver, sessionId: string, appName: string);
|
|
24
23
|
install(): void;
|
|
25
24
|
uninstall(): void;
|
|
@@ -14,7 +14,6 @@ class XMLHttpRequestInterceptor {
|
|
|
14
14
|
this.sessionId = sessionId;
|
|
15
15
|
this.appName = appName;
|
|
16
16
|
this.isInstalled = false;
|
|
17
|
-
this.isIntercepting = false; // Flag para prevenir re-intercepção
|
|
18
17
|
}
|
|
19
18
|
install() {
|
|
20
19
|
if (this.isInstalled) {
|
|
@@ -55,10 +54,6 @@ class XMLHttpRequestInterceptor {
|
|
|
55
54
|
this.originalSend = originalXHR.send;
|
|
56
55
|
originalXHR.send = function (body) {
|
|
57
56
|
const xhr = this;
|
|
58
|
-
// Evitar re-intercepção: se já estamos interceptando, usar send original
|
|
59
|
-
if (self.isIntercepting) {
|
|
60
|
-
return self.originalSend.apply(this, [body]);
|
|
61
|
-
}
|
|
62
57
|
const method = (xhr._fluwaMethod || 'GET');
|
|
63
58
|
const url = xhr._fluwaUrl;
|
|
64
59
|
const requestId = xhr._fluwaRequestId;
|
|
@@ -74,8 +69,6 @@ class XMLHttpRequestInterceptor {
|
|
|
74
69
|
appName: self.appName,
|
|
75
70
|
source: types_1.RequestSource.REAL,
|
|
76
71
|
};
|
|
77
|
-
// Marcar que estamos interceptando para evitar re-intercepção
|
|
78
|
-
self.isIntercepting = true;
|
|
79
72
|
// Verificar se há mock
|
|
80
73
|
self.mockResolver.resolve(method, url)
|
|
81
74
|
.then((mockResponse) => {
|
|
@@ -107,18 +100,37 @@ class XMLHttpRequestInterceptor {
|
|
|
107
100
|
requestMetadata.status = xhr.status;
|
|
108
101
|
// Tentar extrair response
|
|
109
102
|
try {
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
// responseText só está disponível para responseType 'text' ou '' (padrão)
|
|
104
|
+
if (xhr.responseType === '' || xhr.responseType === 'text') {
|
|
105
|
+
if (xhr.responseText) {
|
|
106
|
+
requestMetadata.response = self.safeParseBody(xhr.responseText);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else if (xhr.response) {
|
|
110
|
+
// Para blob, arraybuffer, document, etc., usar xhr.response
|
|
111
|
+
if (typeof xhr.response === 'string') {
|
|
112
|
+
requestMetadata.response = self.safeParseBody(xhr.response);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// Não consegue serializar blob/arraybuffer, apenas registra tipo
|
|
116
|
+
requestMetadata.response = `[${xhr.responseType}]`;
|
|
117
|
+
}
|
|
112
118
|
}
|
|
113
119
|
}
|
|
114
120
|
catch (e) {
|
|
115
|
-
|
|
121
|
+
// Em caso de erro, tenta responseText como fallback
|
|
122
|
+
try {
|
|
123
|
+
if (xhr.responseText) {
|
|
124
|
+
requestMetadata.response = xhr.responseText;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
requestMetadata.response = undefined;
|
|
129
|
+
}
|
|
116
130
|
}
|
|
117
131
|
const duration = Date.now() - (xhr._fluwaStartTime || 0);
|
|
118
132
|
requestMetadata.duration = duration;
|
|
119
133
|
self.requestLogger.logComplete(requestMetadata).catch(() => { });
|
|
120
|
-
// Restaurar a flag quando requisição completar
|
|
121
|
-
self.isIntercepting = false;
|
|
122
134
|
}
|
|
123
135
|
// Chamar handler original
|
|
124
136
|
if (originalOnReadyStateChange) {
|