Skip to content

Commit

Permalink
chore: do not log errors which are handled by Web SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
samialdury committed Apr 13, 2023
1 parent 3c52be9 commit a79b46f
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/proxy/handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/no-named-as-default-member */
import { IncomingMessage, ServerResponse } from 'http'
import { IncomingMessage, ServerResponse, type IncomingHttpHeaders } from 'http'

import undici from 'undici'

Expand Down Expand Up @@ -65,17 +65,41 @@ async function pipeResponse(
}
)
} catch (err) {
handleStreamError(url, outgoingHeaders, res, err)
}
}

function handleStreamError(
url: string,
outgoingHeaders: IncomingHttpHeaders,
res: ServerResponse,
err: unknown
): void {
if (
err &&
(err as Record<string, unknown>)['code'] === 'ECONNRESET' &&
(err as Record<string, unknown>)['message'] === 'aborted'
) {
logger.debug(
{
url,
outgoingHeaders,
err,
},
'Request aborted by the client. Smartlook Web SDK will retry the request later'
)
} else {
logger.warn(
{
url,
outgoingHeaders,
err,
},
'Error while piping response. This is just a warning and you can safely ignore it, since Smartlook Web SDK will retry the request later'
'Request could not be satisfied. This is just a warning and you can safely ignore it, since Smartlook Web SDK will retry the request later'
)

internalError(res)
}

internalError(res)
}

export async function handler(
Expand Down

0 comments on commit a79b46f

Please sign in to comment.