Skip to content

Commit 924a1ea

Browse files
committed
Clear timeout on fetch errors and update stack parser logging
Ensures the timeout is cleared in fetchTimer when a fetch error occurs, preventing potential memory leaks. Also comments out a log statement in stackParser for cleaner error handling. Version bumped to 3.2.12.
1 parent 001c8ab commit 924a1ea

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@hawk.so/javascript",
33
"type": "commonjs",
4-
"version": "3.2.11",
4+
"version": "3.2.12",
55
"description": "JavaScript errors tracking for Hawk.so",
66
"files": [
77
"dist"

src/modules/fetchTimer.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ export default function fetchTimer(url: string, ms: number): Promise<any> {
2525
log('Request is too long, aborting...', 'log', url);
2626
}, ms);
2727

28-
return fetchPromise.then((response) => {
29-
clearTimeout(timeoutId);
28+
return fetchPromise
29+
.then((response) => {
30+
clearTimeout(timeoutId);
3031

31-
return response;
32-
});
32+
return response;
33+
})
34+
.catch((error) => {
35+
clearTimeout(timeoutId);
36+
37+
/**
38+
* Re-throw the error so it can be handled by the caller
39+
*/
40+
throw error;
41+
});
3342
}

src/modules/stackParser.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class StackParser {
2626
const sourceCode = await this.extractSourceCode(frame);
2727
const file = frame.fileName !== null && frame.fileName !== undefined ? frame.fileName : '';
2828
const line = frame.lineNumber !== null && frame.lineNumber !== undefined ? frame.lineNumber : 0;
29-
29+
3030
return {
3131
file,
3232
line,
@@ -146,8 +146,7 @@ export default class StackParser {
146146

147147
return await this.sourceFilesCache[fileName];
148148
} catch (error) {
149-
log('Can not load source file. Skipping...');
150-
149+
// log('Can not load source file. Skipping...');
151150
return null;
152151
}
153152
}

0 commit comments

Comments
 (0)