Skip to content

Commit

Permalink
404 on non existent container path
Browse files Browse the repository at this point in the history
  • Loading branch information
bourgeoa committed Feb 26, 2024
1 parent 74133e6 commit 2e39e97
Show file tree
Hide file tree
Showing 5 changed files with 435 additions and 189 deletions.
2 changes: 1 addition & 1 deletion lib/ldp.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class LDP {
({ path, contentType } = await this.resourceMapper.mapUrlToFile({ url: options, searchIndex }))
stats = await this.stat(path)
} catch (err) {
throw error(404, 'Can\'t find file requested: ' + options)
throw error(err.status || 500, err.message)
}

// Just return, since resource exists
Expand Down
6 changes: 4 additions & 2 deletions lib/resource-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class ResourceMapper {

// Find a file with the same name (minus the dollar extension)
let match = ''
if (match === '') { // always true to keep indentation
try {
const files = await this._readdir(folder)
// Search for files with the same name (disregarding a dollar extension)
if (!isFolder) {
Expand All @@ -134,13 +134,15 @@ class ResourceMapper {
} else if (searchIndex && files.includes(this._indexFilename)) {
match = this._indexFilename
}
} catch (err) {
throw new HTTPError(404, `${filePath} Resource not found`)
}
// Error if no match was found (unless URL ends with '/', then fall back to the folder)
if (match === undefined) {
if (isIndex) {
match = ''
} else {
throw new HTTPError(404, `Resource not found: ${pathname}`)
throw new HTTPError(404, `${pathname} Resource not found`)
}
}
path = `${folder}${match}`
Expand Down
Loading

0 comments on commit 2e39e97

Please sign in to comment.