Skip to content

Commit d12463a

Browse files
megothrubensworks
authored andcommitted
Changed HTTP status when no ACL is found
1 parent 78bb77b commit d12463a

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

lib/acl-checker.js

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,45 @@ class ACLChecker {
132132
// let directory = null
133133
// Create a cascade of reject handlers (one for each possible ACL)
134134
const possibleACLs = this.getPossibleACLs()
135-
const nearestACL = possibleACLs.reduce((prevACL, acl) => {
136-
return prevACL.catch(() => new Promise((resolve, reject) => {
137-
this.fetch(acl, (err, graph) => {
138-
if (err && err.code !== 'ENOENT') {
139-
isContainer = true
140-
reject(err)
141-
} else {
142-
const relative = resource.replace(acl.replace(/[^/]+$/, ''), './')
143-
debug(`Using ACL ${acl} for ${relative}`)
144-
resolve({ acl, graph, isContainer })
145-
}
146-
})
147-
}))
148-
}, Promise.reject())
149-
return nearestACL.catch(e => { throw new Error(`No ACL resource found, searched in \n- ${possibleACLs.join('\n- ')}`) })
135+
const acls = [...possibleACLs]
136+
let returnAcl = null
137+
while (possibleACLs.length > 0 && !returnAcl) {
138+
const acl = possibleACLs.shift()
139+
try {
140+
const graph = await this.fetch(acl)
141+
const relative = resource.replace(acl.replace(/[^/]+$/, ''), './')
142+
debug(`Using ACL ${acl} for ${relative}`)
143+
returnAcl = { acl, graph, isContainer }
144+
} catch (err) {
145+
if (err && (err.code === 'ENOENT' || err.status === 404)) {
146+
isContainer = true
147+
continue
148+
} else if (err) {
149+
console.error('ERROR IN getNearestACL', err.code, err)
150+
debug(err)
151+
throw err
152+
}
153+
}
154+
}
155+
if (!returnAcl) {
156+
throw new HTTPError(500, `No ACL found for ${resource}, searched in \n- ${acls.join('\n- ')}`)
157+
}
158+
return returnAcl
159+
// const nearestACL = possibleACLs.reduce((prevACL, acl) => {
160+
// return prevACL.catch(() => new Promise((resolve, reject) => {
161+
// this.fetch(acl, (err, graph) => {
162+
// if (err && err.code !== 'ENOENT') {
163+
// isContainer = true
164+
// reject(err)
165+
// } else {
166+
// const relative = resource.replace(acl.replace(/[^/]+$/, ''), './')
167+
// debug(`Using ACL ${acl} for ${relative}`)
168+
// resolve({ acl, graph, isContainer })
169+
// }
170+
// })
171+
// }))
172+
// }, Promise.reject())
173+
// return nearestACL.catch(e => { throw new Error(`No ACL resource found, searched in \n- ${possibleACLs.join('\n- ')}`) })
150174
}
151175

152176
// Gets all possible ACL paths that apply to the resource

0 commit comments

Comments
 (0)