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
46a77657
Commit
46a77657
authored
2 years ago
by
richard.petersen
Committed by
richard.petersen
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve error handling in case the UI-containers are not accessible
parent
a34e2102
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
+45
-0
45 additions, 0 deletions
spec/file_caching_test.js
src/errors.js
+6
-1
6 additions, 1 deletion
src/errors.js
src/files.js
+5
-2
5 additions, 2 deletions
src/files.js
with
56 additions
and
3 deletions
spec/file_caching_test.js
+
45
−
0
View file @
46a77657
...
...
@@ -268,6 +268,51 @@ describe('File caching service', function () {
expect
(
response5
.
text
).
to
.
equal
(
'
second
'
)
})
it
(
'
checks again for files after an error occurred
'
,
async
function
()
{
// we have example.js in both files. the first one will be overwritten and therefore not be called
mockFetch
({
'
http://ui-server
'
:
{
'
/manifest.json
'
:
generateSimpleViteManifest
({
'
example.js
'
:
{
}
}),
'
/example.js
'
:
td
.
when
(
td
.
func
()(
td
.
matchers
.
anything
())).
thenReturn
(
new
Response
(
'
UI-container not available
'
,
{
headers
:
{
'
content-type
'
:
'
text/plain
'
},
status
:
503
}),
new
Response
(
'
Now available
'
,
{
headers
:
{
'
content-type
'
:
'
text/plain
'
}
})
)
}
})
app
=
await
mockApp
()
const
response1
=
await
request
(
app
.
server
).
get
(
'
/example.js
'
)
expect
(
response1
.
statusCode
).
to
.
equal
(
404
)
const
response2
=
await
request
(
app
.
server
).
get
(
'
/example.js
'
)
expect
(
response2
.
statusCode
).
to
.
equal
(
200
)
expect
(
response2
.
text
).
to
.
equal
(
'
Now available
'
)
})
it
(
'
does not check again, when a 404 occurred
'
,
async
function
()
{
// we have example.js in both files. the first one will be overwritten and therefore not be called
mockFetch
({
'
http://ui-server
'
:
{
'
/manifest.json
'
:
generateSimpleViteManifest
({
'
example.js
'
:
{
}
}),
'
/example.js
'
:
td
.
when
(
td
.
func
()(
td
.
matchers
.
anything
())).
thenReturn
(
new
Response
(
'
Not found
'
,
{
headers
:
{
'
content-type
'
:
'
text/plain
'
},
status
:
404
}),
new
Response
(
'
Now found
'
,
{
headers
:
{
'
content-type
'
:
'
text/plain
'
}
})
)
}
})
app
=
await
mockApp
()
const
response1
=
await
request
(
app
.
server
).
get
(
'
/example.js
'
)
expect
(
response1
.
statusCode
).
to
.
equal
(
404
)
const
response2
=
await
request
(
app
.
server
).
get
(
'
/example.js
'
)
expect
(
response2
.
statusCode
).
to
.
equal
(
404
)
})
it
(
'
only fetches files once, even when requested simultanously
'
,
async
function
()
{
let
spy
mockFetch
({
...
...
This diff is collapsed.
Click to expand it.
src/errors.js
+
6
−
1
View file @
46a77657
export
class
NotFoundError
extends
Error
{}
export
class
NotFoundError
extends
Error
{
constructor
(
message
,
options
)
{
super
(
message
,
options
)
this
.
status
=
options
.
status
}
}
This diff is collapsed.
Click to expand it.
src/files.js
+
5
−
2
View file @
46a77657
...
...
@@ -41,7 +41,7 @@ export async function fetchFileWithHeadersFromBaseUrl (path, baseUrl, version) {
if
(
!
response
.
ok
)
{
if
(
response
.
status
===
404
)
logger
.
trace
(
`[Files] "
${
path
}
" could not be found on "
${
baseUrl
}
". Responded with:
${
response
.
status
}
`
)
else
logger
.
error
(
`[Files] Unexpected result from file retrieval "
${
path
}
" on "
${
baseUrl
}
", responded with:
${
response
.
status
}
`
)
throw
new
NotFoundError
(
`Error fetching file:
${
path
}
`
)
throw
new
NotFoundError
(
`Error fetching file:
${
path
}
`
,
{
status
:
response
.
status
}
)
}
const
result
=
{
...
...
@@ -101,7 +101,10 @@ export function getFile ({ version, path }) {
}
}
const
dataFromServer
=
await
fetchFileWithHeaders
({
version
,
path
})
const
dataFromServer
=
await
fetchFileWithHeaders
({
version
,
path
}).
catch
(
err
=>
{
if
(
err
.
status
!==
404
)
delete
cache
.
getCache
()[
key
]
throw
err
})
if
(
redis
.
isEnabled
())
{
logger
.
debug
(
`[Files] Store in redis:
${
key
}
`
)
const
{
body
,
...
rest
}
=
dataFromServer
...
...
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