Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
f334fe52
Commit
f334fe52
authored
5 years ago
by
Neuber, Eugen Ramon
Committed by
Reiter, Christoph
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve ERROR message on XHR/fetch for non-JSON-LD
See issue VPU/Middleware/API#9
parent
9aee1491
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/common/error.js
+36
-15
36 additions, 15 deletions
packages/common/error.js
with
36 additions
and
15 deletions
packages/common/error.js
+
36
−
15
View file @
f334fe52
...
@@ -10,23 +10,35 @@ import {i18n} from "./i18n";
...
@@ -10,23 +10,35 @@ import {i18n} from "./i18n";
* @param icon
* @param icon
*/
*/
export
const
handleXhrError
=
(
jqXHR
,
textStatus
,
errorThrown
,
icon
=
"
sad
"
)
=>
{
export
const
handleXhrError
=
(
jqXHR
,
textStatus
,
errorThrown
,
icon
=
"
sad
"
)
=>
{
if
(
textStatus
!==
"
abort
"
)
{
// return if user aborted the request
// try to show hydra error text
if
(
textStatus
===
"
abort
"
)
{
let
body
=
jqXHR
.
responseJSON
!==
undefined
&&
jqXHR
.
responseJSON
[
"
hydra:description
"
]
!==
undefined
?
return
;
jqXHR
.
responseJSON
[
"
hydra:description
"
]
:
textStatus
;
}
// if the server is not reachable at all
let
body
;
if
(
jqXHR
.
status
===
0
)
{
body
=
i18n
.
t
(
'
error.connection-to-server-refused
'
);
}
notify
({
if
(
jqXHR
.
responseJSON
!==
undefined
&&
jqXHR
.
responseJSON
[
"
hydra:description
"
]
!==
undefined
)
{
"
summary
"
:
i18n
.
t
(
'
error.summary
'
),
// response is a JSON-LD
"
body
"
:
body
,
body
=
jqXHR
.
responseJSON
[
"
hydra:description
"
];
"
icon
"
:
icon
,
}
else
if
(
jqXHR
.
responseJSON
!==
undefined
&&
jqXHR
.
responseJSON
[
'
detail
'
]
!==
undefined
)
{
"
type
"
:
"
danger
"
,
// response is a plain JSON
});
body
=
jqXHR
.
responseJSON
[
'
detail
'
];
}
else
{
// no description available
body
=
textStatus
;
}
// if the server is not reachable at all
if
(
jqXHR
.
status
===
0
)
{
body
=
i18n
.
t
(
'
error.connection-to-server-refused
'
);
}
}
notify
({
"
summary
"
:
i18n
.
t
(
'
error.summary
'
),
"
body
"
:
body
,
"
icon
"
:
icon
,
"
type
"
:
"
danger
"
,
});
};
};
/**
/**
...
@@ -46,7 +58,16 @@ export const handleFetchError = async (error, summary = "", icon = "sad") => {
...
@@ -46,7 +58,16 @@ export const handleFetchError = async (error, summary = "", icon = "sad") => {
try
{
try
{
await
error
.
json
().
then
((
json
)
=>
{
await
error
.
json
().
then
((
json
)
=>
{
body
=
json
[
"
hydra:description
"
]
!==
undefined
?
json
[
"
hydra:description
"
]
:
error
.
statusText
;
if
(
json
[
"
hydra:description
"
]
!==
undefined
)
{
// response is a JSON-LD
body
=
json
[
"
hydra:description
"
];
}
else
if
(
json
[
'
detail
'
]
!==
undefined
)
{
// response is a plain JSON
body
=
json
[
'
detail
'
];
}
else
{
// no description available
body
=
error
.
statusText
;
}
}).
catch
(()
=>
{
}).
catch
(()
=>
{
body
=
error
.
statusText
!==
undefined
?
error
.
statusText
:
error
;
body
=
error
.
statusText
!==
undefined
?
error
.
statusText
:
error
;
});
});
...
...
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