Skip to content

Commit

Permalink
refactor: 简化上报的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Jun 18, 2024
1 parent 84ca717 commit 03400c5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {tmpdir} from 'os'
import pMap from 'p-map'
import pRetry from 'p-retry'
import {basename, dirname, join} from 'path'
import {serializeError} from 'serialize-error'
import {connect, Socket} from 'socket.io-client'
import {Tail} from 'tail'
import {fileURLToPath} from 'url'
Expand Down Expand Up @@ -211,24 +210,25 @@ export class Cluster {
{
retries: 10,
onFailedAttempt: async (e) => {
if (e.cause instanceof HTTPError) {
const cause = e.cause
if (cause instanceof HTTPError) {
logger.debug(
{redirectUrls: e.cause.response.redirectUrls},
`下载文件${file.path}失败: ${e.cause.response.statusCode}`,
{redirectUrls: cause.response.redirectUrls},
`下载文件${file.path}失败: ${cause.response.statusCode}`,
)
logger.trace({err: e}, toString(e.cause.response.body))
logger.trace({err: e}, toString(cause.response.body))
} else {
logger.debug({err: e}, `下载文件${file.path}失败,正在重试`)
}

if (e instanceof RequestError) {
const redirectUrls = e.response?.redirectUrls
if (cause instanceof RequestError) {
const redirectUrls = cause.response?.redirectUrls
if (redirectUrls) {
await this.got
.post('openbmclapi/report', {
json: {
urls: redirectUrls,
error: stringifySafe(serializeError(e)),
error: stringifySafe({message: cause.message}),
},
})
.catch((e) => {
Expand Down

0 comments on commit 03400c5

Please sign in to comment.