Skip to content

Commit 2da77b0

Browse files
committed
refactor: Add Debugging for Failed Notifications
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.
1 parent c933a74 commit 2da77b0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/debug.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ exports.accounts = debug('solid:accounts')
1515
exports.email = debug('solid:email')
1616
exports.ldp = debug('solid:ldp')
1717
exports.fs = debug('solid:fs')
18+
exports.prep = debug('solid:prep')

lib/handlers/notify.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const libPath = require('path/posix')
44

55
const headerTemplate = require('express-prep/templates').header
66
const solidRDFTemplate = require('../rdf-notification-template')
7+
const debug = require('../debug').prep
78

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

8994
// Write a notification to parent container
9095
// POST in Solid creates a child resource
9196
const parent = getParent(path)
9297
if (parent && method !== 'POST') {
98+
const parentID = res.setEventID(parent)
99+
const parentUrl = new URL(parent, fullUrl)
93100
try {
94-
const parentID = res.setEventID(parent)
95-
const parentUrl = new URL(parent, fullUrl)
96101
trigger({
97102
path: parent,
98103
generateNotification (
@@ -115,7 +120,11 @@ function handler (req, res, next) {
115120
}
116121
})
117122
} catch (error) {
118-
// Failed notification message
123+
debug(`Failed to trigger notification on parent route ${parentUrl}`)
124+
// No special handling is necessary since the resource mutation was
125+
// already successful. The purpose of this block is to prevent Express
126+
// from triggering error handling middleware when notifications fail.
127+
// An error notification might be sent in the future.
119128
}
120129
}
121130

0 commit comments

Comments
 (0)