Skip to content

Commit

Permalink
refactor: Add Debugging for Failed Notifications
Browse files Browse the repository at this point in the history
Added debugging statements for failed notifications. Also clarified that notification errors should not be passed on to Express for error handling, since the mutation that triggered the notification was already successful.
  • Loading branch information
CxRes committed Oct 23, 2024
1 parent c933a74 commit 2da77b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ exports.accounts = debug('solid:accounts')
exports.email = debug('solid:email')
exports.ldp = debug('solid:ldp')
exports.fs = debug('solid:fs')
exports.prep = debug('solid:prep')
17 changes: 13 additions & 4 deletions lib/handlers/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const libPath = require('path/posix')

const headerTemplate = require('express-prep/templates').header
const solidRDFTemplate = require('../rdf-notification-template')
const debug = require('../debug').prep

const ALLOWED_RDF_MIME_TYPES = [
'application/ld+json',
Expand Down Expand Up @@ -82,17 +83,21 @@ function handler (req, res, next) {
}
})
} catch (error) {
// Failed notification message
debug(`Failed to trigger notification on route ${fullUrl}`)
// No special handling is necessary since the resource mutation was
// already successful. The purpose of this block is to prevent Express
// from triggering error handling middleware when notifications fail.
// An error notification might be sent in the future.
}
}

// Write a notification to parent container
// POST in Solid creates a child resource
const parent = getParent(path)
if (parent && method !== 'POST') {
const parentID = res.setEventID(parent)
const parentUrl = new URL(parent, fullUrl)
try {
const parentID = res.setEventID(parent)
const parentUrl = new URL(parent, fullUrl)
trigger({
path: parent,
generateNotification (
Expand All @@ -115,7 +120,11 @@ function handler (req, res, next) {
}
})
} catch (error) {
// Failed notification message
debug(`Failed to trigger notification on parent route ${parentUrl}`)
// No special handling is necessary since the resource mutation was
// already successful. The purpose of this block is to prevent Express
// from triggering error handling middleware when notifications fail.
// An error notification might be sent in the future.
}
}

Expand Down

0 comments on commit 2da77b0

Please sign in to comment.