Skip to content

Commit

Permalink
Fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Lezek123 committed Oct 16, 2024
1 parent ec6a278 commit 1beb710
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions storage-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Fix `util:cleanup` script (call `loadDataObjectIdCache` first)
- Allow changing default log level using environment variable (`COLOSSUS_DEFAULT_LOG_LEVEL`)
- Allow adjusting cleanup constants via env (`CLEANUP_MIN_REPLICATION_THRESHOLD`, `CLEANUP_NEW_OBJECT_EXPIRATION_PERIOD`)
- Error handling: Clearer warning messages if unexpected response encountered during sync (ie. 404)

### 4.1.2

Expand Down
11 changes: 4 additions & 7 deletions storage-node/src/services/sync/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs'
import _ from 'lodash'
import path from 'path'
import { pipeline } from 'stream'
import superagent from 'superagent'
import superagent, { Response } from 'superagent'
import urljoin from 'url-join'
import { promisify } from 'util'
import { v4 as uuidv4 } from 'uuid'
Expand Down Expand Up @@ -138,9 +138,9 @@ export class DownloadFileTask implements SyncTask {
.set('X-COLOSSUS-HOST-ID', this.hostId) as unknown as NodeJS.ReadableStream
const fileStream = fs.createWriteStream(tempFilePath)

request.on('response', (res) => {
if (!res.ok && res.statusCode !== 404) {
logger.warn(`Sync - unexpected status code(${res.statusCode}) for ${res?.request?.url}`)
request.on('response', (res: Response) => {
if (!res.ok) {
request.emit('error', `request failed: ${res.error}`)
}

// Handle 'error' event on Response too, because it will be emitted if request was
Expand All @@ -151,9 +151,6 @@ export class DownloadFileTask implements SyncTask {
})
})

request.on('error', (err) => {
logger.warn(`Sync - fetching data error for ${url}: ${err}`, { err })
})
await streamPipeline(request, fileStream)
await this.verifyDownloadedFile(tempFilePath)
await moveFile(tempFilePath, filepath)
Expand Down

0 comments on commit 1beb710

Please sign in to comment.