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
61e8266e
Unverified
Commit
61e8266e
authored
4 years ago
by
Bekerle, Patrizio
Browse files
Options
Downloads
Patches
Plain Diff
Remove unused handleXhrError and handleFetchError functions
parent
45e1c6d8
No related branches found
No related tags found
No related merge requests found
Pipeline
#16931
passed with warnings
4 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/common/error.js
+0
-85
0 additions, 85 deletions
packages/common/error.js
with
0 additions
and
85 deletions
packages/common/error.js
+
0
−
85
View file @
61e8266e
import
{
send
as
notify
}
from
'
./notification
'
;
import
{
i18n
}
from
"
./i18n
"
;
/**
* Error handling for XHR errors
*
* @param jqXHR
* @param textStatus
* @param errorThrown
* @param icon
*/
export
const
handleXhrError
=
(
jqXHR
,
textStatus
,
errorThrown
,
icon
=
"
sad
"
)
=>
{
// return if user aborted the request
if
(
textStatus
===
"
abort
"
)
{
return
;
}
let
body
;
if
(
jqXHR
.
responseJSON
!==
undefined
&&
jqXHR
.
responseJSON
[
"
hydra:description
"
]
!==
undefined
)
{
// response is a JSON-LD
body
=
jqXHR
.
responseJSON
[
"
hydra:description
"
];
}
else
if
(
jqXHR
.
responseJSON
!==
undefined
&&
jqXHR
.
responseJSON
[
'
detail
'
]
!==
undefined
)
{
// 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
"
:
escapeHTML
(
stripHTML
(
body
)),
"
icon
"
:
icon
,
"
type
"
:
"
danger
"
,
});
};
/**
* Error handling for fetch errors
*
* @param error
* @param summary
* @param icon
*/
export
const
handleFetchError
=
async
(
error
,
summary
=
""
,
icon
=
"
sad
"
)
=>
{
// return if user aborted the request
if
(
error
.
name
===
"
AbortError
"
)
{
return
;
}
let
body
;
try
{
await
error
.
json
().
then
((
json
)
=>
{
if
(
json
[
"
hydra:description
"
]
!==
undefined
)
{
// response is a JSON-LD and possibly also contains HTML!
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
(()
=>
{
body
=
error
.
statusText
!==
undefined
?
error
.
statusText
:
error
;
});
}
catch
(
e
)
{
// a TypeError means the connection to the server was refused most of the times
if
(
error
.
name
===
"
TypeError
"
)
{
body
=
error
.
message
!==
""
?
error
.
message
:
i18n
.
t
(
'
error.connection-to-server-refused
'
);
}
}
notify
({
"
summary
"
:
summary
===
""
?
i18n
.
t
(
'
error.summary
'
)
:
summary
,
"
body
"
:
escapeHTML
(
stripHTML
(
body
)),
"
icon
"
:
icon
,
"
type
"
:
"
danger
"
,
});
};
/**
* Escapes html
*
...
...
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