@@ -43,6 +43,10 @@ const permissions = mergeAll([
4343 organizationPermissions
4444] )
4545
46+ function isApiRequest ( { path } ) {
47+ return path . indexOf ( '/api' ) === 0
48+ }
49+
4650/**
4751 * Check if a user has a specific permission
4852 *
@@ -159,18 +163,27 @@ function check (ability) {
159163 if ( allowed ) {
160164 next ( )
161165 } else {
162- res . boom . unauthorized ( 'Forbidden' )
166+ if ( isApiRequest ( req ) ) {
167+ res . boom . unauthorized ( 'Forbidden' )
168+ } else {
169+ next ( new Error ( 'Forbidden' ) )
170+ }
163171 }
164172 } catch ( e ) {
165173 console . error ( 'error checking permission' , e )
166- // An error occurred checking the permissions
167- // if user id is missing it's an authentication problem
168- if ( e . message . includes ( 'osm id is required' ) ) {
169- return res . boom . unauthorized ( 'Forbidden' )
170- }
171174
172- // otherwise it could be the resource not existing, we send 404
173- res . boom . notFound ( 'Could not find resource' )
175+ if ( isApiRequest ( req ) ) {
176+ // Handle API request errors
177+ if ( e . message . includes ( 'osm id is required' ) ) {
178+ return res . boom . unauthorized ( 'Forbidden' )
179+ }
180+
181+ // otherwise it could be the resource not existing, we send 404
182+ res . boom . notFound ( 'Could not find resource' )
183+ } else {
184+ // This should be web page errors, which are handled at app/index.js#L60
185+ next ( new Error ( 'Forbidden' ) )
186+ }
174187 }
175188 }
176189}
0 commit comments