Skip to content

Commit

Permalink
fix: better handling for unfound id in Update
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Prodromou <[email protected]>
  • Loading branch information
Evan Prodromou committed Jan 7, 2024
1 parent 8baa76a commit 9d78a3c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ class Activity extends ActivityObject {
throw new createError.BadRequest('No id for object to update')
}
const object = await ActivityObject.getById(activity.object.id, actorObj)
if (!object) {
throw new createError.BadRequest(`Unable to get object ${activity.object.id}`)
}
const objectOwner = await object.owner()
if (!objectOwner || await objectOwner.id() !== await actorObj.id()) {
throw new createError.BadRequest("You can't update an object you don't own")
Expand Down Expand Up @@ -3313,10 +3316,10 @@ app.post('/:type/:id',
}))

app.use((err, req, res, next) => {
logger.silly(err.stack)
if (createError.isHttpError(err)) {
if (err.statusCode > 500) {
logger.error(`Error status ${err.statusCode}: `, err)
logger.debug(err.stack)
}
res.status(err.statusCode)
if (res.expose) {
Expand All @@ -3334,19 +3337,20 @@ app.use((err, req, res, next) => {
res.json({ error_description: err.message, error: 'invalid_token' })
} else {
logger.error('Error status 500: ', err)
logger.debug(err.stack)
res.status(500)
res.json({ message: err.message })
}
})

process.on('unhandledRejection', (err) => {
logger.error('Unhandled rejection: ', err)
logger.silly(err.stack)
logger.debug(err.stack)
})

process.on('uncaughtException', (err) => {
logger.error('Uncaught exception: ', err)
logger.silly(err.stack)
logger.debug(err.stack)
})

// Define a function for cleanup tasks
Expand Down

0 comments on commit 9d78a3c

Please sign in to comment.