Skip to content

Commit

Permalink
convert err obj into JSON stringifiable object + update error msg (#1376
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vicky-g committed Apr 5, 2021
1 parent d9ae89b commit d8f50b7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions creator-node/src/apiHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ const sendResponseWithHeartbeatTerminator =
} else {
logger.info('Error processing request:', resp.object.error)
}

// Converts the error object into an object that JSON.stringify can parse
if (resp.object.error) {
resp.object.error = Object.getOwnPropertyNames(resp.object.error).reduce((acc, cur) => { acc[cur] = resp.object.error[cur]; return acc }, {})
}
}

// Construct the remainder of the JSON response
Expand Down
2 changes: 1 addition & 1 deletion creator-node/src/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ module.exports = function (app) {
// Ensure actual and expected dirCIDs match
const expectedDirCID = ipfsAddRespArr[ipfsAddRespArr.length - 1].cid.toString()
if (expectedDirCID !== dirCID) {
throw new Error(`Image file validation failed - dirCIDs do not match for dirCID ${dirCID}`)
throw new Error(`Image file validation failed - dirCIDs do not match for dirCID=${dirCID} expectedCID=${expectedDirCID}`)
}

// Record image file entries in DB
Expand Down
5 changes: 3 additions & 2 deletions libs/src/services/creatorNode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,14 @@ class CreatorNode {
}
)
if (resp.data && resp.data.error) {
throw new Error(resp.data.error)
throw new Error(JSON.stringify(resp.data.error))
}
onProgress(total, total)
return resp.data
} catch (e) {
if (!e.response && retries > 0) {
console.log(`Network Error in request ${requestId} with ${retries} retries... retrying`)
console.warn(`Network Error in request ${requestId} with ${retries} retries... retrying`)
console.warn(e)
return this._uploadFile(file, route, onProgress, extraFormDataOptions, retries - 1)
}
await this._handleErrorHelper(e, url, requestId)
Expand Down

0 comments on commit d8f50b7

Please sign in to comment.