Skip to content

Commit f996761

Browse files
committed
Allow linksHandler to map resources that do (not) exist yet
1 parent 692b4e2 commit f996761

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/header.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ function addLinks (res, fileMetadata) {
4343

4444
async function linksHandler (req, res, next) {
4545
const ldp = req.app.locals.ldp
46-
const { path: filename } = await ldp.resourceMapper.mapUrlToFile(req)
46+
let filename
47+
try {
48+
// Hack: createIfNotExists is set to true for PUT or PATCH requests
49+
// because the file does not exist yet at this point.
50+
// But it will be created afterwards.
51+
// This should be improved with the new server architecture.
52+
({ path: filename } = await ldp.resourceMapper
53+
.mapUrlToFile({ url: req, createIfNotExists: req.method === 'PUT' || req.method === 'PATCH' }))
54+
} catch (e) {
55+
// Silently ignore errors here
56+
// Later handlers will error as well, but they will be able to given a more concrete error message (like 400 or 404)
57+
return next()
58+
}
4759

4860
if (path.extname(filename) === ldp.suffixMeta) {
4961
debug.metadata('Trying to access metadata file as regular file.')

0 commit comments

Comments
 (0)