Skip to content

Commit

Permalink
DereferenceMixin: if a resource is not dereferenceable, show its URI
Browse files Browse the repository at this point in the history
  • Loading branch information
srosset81 committed Feb 11, 2025
1 parent 7cbb19f commit ee76c9e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/middleware/packages/ldp/mixins/dereference.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,24 @@ module.exports = {
// If ref not defined or if it's a resolved object with no id (created by blank nodes)...
if (typeof reference !== 'string' && !reference?.['@id'] && !reference?.id) return reference;

const resourceUri = reference['@id'] || reference.id || reference;

// Get the resource.
let result = await ctx.call('ldp.resource.get', {
resourceUri: reference['@id'] || reference.id || reference,
accept: MIME_TYPES.JSON
});
// Delete the context from the result
delete result['@context'];
return result;
try {
let result = await ctx.call('ldp.resource.get', {
resourceUri,
accept: MIME_TYPES.JSON
});
// Delete the context from the result
delete result['@context'];
return result;
} catch (e) {
if (e.code === 403 || e.code === 404) {
return resourceUri;
} else {
throw e;
}
}
},

/**
Expand Down

0 comments on commit ee76c9e

Please sign in to comment.