From 2da77b01f71a5b4c2023f7376fad3c26e5afed8a Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Wed, 23 Oct 2024 20:40:44 +0530 Subject: [PATCH] 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. --- lib/debug.js | 1 + lib/handlers/notify.js | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/debug.js b/lib/debug.js index 306ee2bfb..7f16654ee 100644 --- a/lib/debug.js +++ b/lib/debug.js @@ -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') diff --git a/lib/handlers/notify.js b/lib/handlers/notify.js index 6adedf97e..fe758da12 100644 --- a/lib/handlers/notify.js +++ b/lib/handlers/notify.js @@ -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', @@ -82,7 +83,11 @@ 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. } } @@ -90,9 +95,9 @@ function handler (req, res, next) { // 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 ( @@ -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. } }