Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ui-middleware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source Software
OX App Suite
Core
ui-middleware
Commits
aa43d2a5
Commit
aa43d2a5
authored
1 year ago
by
david.bauer
Browse files
Options
Downloads
Patches
Plain Diff
Change: Error handling improved
parent
1fa1aaaf
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
spec/file_caching_test.js
+1
-1
1 addition, 1 deletion
spec/file_caching_test.js
src/errors.js
+2
-2
2 additions, 2 deletions
src/errors.js
src/routes/serve-files.js
+1
-2
1 addition, 2 deletions
src/routes/serve-files.js
with
4 additions
and
5 deletions
spec/file_caching_test.js
+
1
−
1
View file @
aa43d2a5
...
...
@@ -292,7 +292,7 @@ describe('File caching service', function () {
app
=
await
injectApp
()
const
response1
=
await
app
.
inject
({
url
:
'
/example.js
'
})
expect
(
response1
.
statusCode
).
to
.
equal
(
404
)
expect
(
response1
.
statusCode
).
to
.
equal
(
503
)
const
response2
=
await
app
.
inject
({
url
:
'
/example.js
'
})
expect
(
response2
.
statusCode
).
to
.
equal
(
200
)
...
...
This diff is collapsed.
Click to expand it.
src/errors.js
+
2
−
2
View file @
aa43d2a5
...
...
@@ -14,7 +14,7 @@ export class VersionMismatchError extends Error {}
*/
export
function
isVersionMismatchError
(
err
)
{
const
errors
=
err
instanceof
AggregateError
?
err
.
errors
:
[
err
]
return
errors
.
reduce
((
memo
,
error
)
=>
memo
&&
error
instanceof
VersionMismatchError
,
true
)
return
errors
.
some
(
error
=>
error
instanceof
VersionMismatchError
)
}
/**
...
...
@@ -24,5 +24,5 @@ export function isVersionMismatchError (err) {
*/
export
function
isNotFoundError
(
err
)
{
const
errors
=
err
instanceof
AggregateError
?
err
.
errors
:
[
err
]
return
errors
.
reduce
((
memo
,
error
)
=>
memo
&&
error
instanceof
NotFoundError
,
true
)
return
errors
.
some
(
error
=>
error
instanceof
NotFoundError
)
}
This diff is collapsed.
Click to expand it.
src/routes/serve-files.js
+
1
−
2
View file @
aa43d2a5
...
...
@@ -9,11 +9,10 @@ export default async function serveFilePlugin (fastify, options) {
const
path
=
url
===
'
/
'
?
'
/index.html
'
:
url
const
{
body
,
headers
}
=
await
getFile
({
version
,
path
})
reply
.
headers
(
headers
)
reply
.
send
(
body
)
}
catch
(
err
)
{
if
(
isNotFoundError
(
err
)
||
isVersionMismatchError
(
err
))
throw
fastify
.
httpErrors
.
createError
(
404
,
`File "
${
req
.
urlData
(
'
path
'
)}
" does not exist.`
)
if
(
isNotFoundError
(
err
)
||
isVersionMismatchError
(
err
))
throw
fastify
.
httpErrors
.
createError
(
404
,
`File "
${
req
.
urlData
(
'
path
'
)}
" does not exist.`
,
err
)
throw
fastify
.
httpErrors
.
createError
(
err
.
statusCode
||
500
,
err
)
}
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment