Skip to content

Commit

Permalink
fix(ssr): Better debugging server-side analytics error responses
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Apr 25, 2024
1 parent 42c3123 commit dadb09a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/ssr/src/lib/analytics-events.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AxiosError } from 'axios';
import { EventEmitter } from 'node:events';
import { warn, error } from 'firebase-functions/logger';
import { getFirestore, Timestamp, FieldValue } from 'firebase-admin/firestore';
Expand Down Expand Up @@ -91,7 +92,27 @@ const sendAnalyticsEvents = async (
for (let i = 0; i < results.length; i++) {
const { status } = results[i];
if (status === 'rejected') {
warn((results[i] as PromiseRejectedResult).reason);
const reason: AxiosError = (results[i] as PromiseRejectedResult).reason;
const err: any = new Error(reason.message);
err.statusCode = reason.response?.status;
if (reason.config) {
err.config = {
url: reason.config.url,
method: reason.config.method,
headers: reason.config.headers,
data: reason.config.data,
};
}
if (reason.response) {
err.response = {
headers: reason.response.headers,
data: reason.response.data,
};
}
warn(err, {
request: err.config,
response: err.response,
});
}
}
}),
Expand Down

0 comments on commit dadb09a

Please sign in to comment.