Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@ export const uploadEvents = async ({
writeKey,
url,
events,
retryCount = 0,
}: {
writeKey: string;
url: string;
events: SegmentEvent[];
}) => {
retryCount?: number;
}): Promise<Response> => {
// Create Authorization header (Basic auth format)
const authHeader = 'Basic ' + btoa(writeKey + ':');

return await fetch(url, {
method: 'POST',
keepalive: true,
body: JSON.stringify({
batch: events,
sentAt: new Date().toISOString(),
writeKey: writeKey,
writeKey: writeKey, // Keep in body for backwards compatibility
}),
headers: {
'Content-Type': 'application/json; charset=utf-8',
'Authorization': authHeader,
'X-Retry-Count': retryCount.toString(),
},
});
};
4 changes: 0 additions & 4 deletions packages/core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,14 @@ export const checkResponseForErrors = (response: Response) => {
* @returns a SegmentError object
*/
export const translateHTTPError = (error: unknown): SegmentError => {
// SegmentError already
if (error instanceof SegmentError) {
return error;
// JSON Deserialization Errors
} else if (error instanceof SyntaxError) {
return new JSONError(
ErrorType.JsonUnableToDeserialize,
error.message,
error
);

// HTTP Errors
} else {
const message =
error instanceof Error
Expand Down
Loading
Loading