Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (errCode !== ERR_CODE_OTHER && i18next.exists(errCode)) {
content = i18next.t(errCode)
} else {
content =
response?.data?.message || err.message || i18next.t(ERR_CODE_OTHER)
}
err.message = content
if (errCode === 'error.api.unauthorized') {
// Handle unauthorized error in a unified way
if (!routing.isLocationMatch('/') && !routing.isSignInPage()) {
message.error({ content, key: errCode })
}
auth.clearAuthToken()
singleSpa.navigateToUrl('#' + routing.signInRoute)
err.handled = true
} else if (errorStrategy === ErrorStrategy.Default) {
if (method === 'get') {
const fullUrl = config.url as string
const API = fullUrl.replace(getBasePath(), '').split('?')[0]
notification.error({
key: API,
message: i18next.t('error.title'),
description: (
<span>
API: {API}
<br>
{content}
</span>
),
})
it(`should call push state when the destination doesn't contain domain and has different path 1`, function() {
singleSpa.navigateToUrl('somethinger#b/my-route');
// If pushState wasn't called, karma will barf because the page will have reloaded if the href was changed directly
expectPathAndHashToEqual('somethinger#b/my-route');
});
instance.interceptors.response.use(undefined, function (err) {
const { response } = err
// Handle unauthorized error in a unified way
if (
response &&
response.data &&
response.data.code === 'error.api.unauthorized'
) {
if (!routing.isLocationMatch('/') && !routing.isSignInPage()) {
message.error(i18next.t('error.message.unauthorized'))
}
auth.clearAuthToken()
singleSpa.navigateToUrl('#' + routing.signInRoute)
err.handled = true
} else if (err.message === 'Network Error') {
message.error(i18next.t('error.message.network'))
err.handled = true
}
return Promise.reject(err)
})
it(`should reload the page to a new url when the origin's don't match, since that's the only way to navigate to a different domain/origin`, function() {
const url = 'https://other-app.com/something#b/my-route';
const opts = {isTestingEnv: true};
const returnValue = singleSpa.navigateToUrl(url, opts);
expect(returnValue).toEqual({wouldHaveReloadedThePage: true})
});
it('should update hash when destination starts with a hash', function() {
singleSpa.navigateToUrl('#a/other');
expect(location.hash).toBe('#a/other');
});
it(`should call push state when the url has no hash`, function() {
singleSpa.navigateToUrl(hrefWithoutHash() + '/some-other-path-without-hash');
expectPathAndHashToEqual('/some-other-path-without-hash');
});
const handleSubmit = usePersistFn(async (form) => {
try {
clearErrorMsg()
setLoading(true)
const r = await client.getInstance().userLogin(fnLoginForm(form), {
errorStrategy: ErrorStrategy.Custom,
})
auth.setAuthToken(r.data.token)
message.success(t('signin.message.success'))
singleSpa.navigateToUrl(successRoute)
} catch (e) {
if (!e.handled) {
setError(t('signin.message.error', { msg: e.message }))
onFailure()
}
} finally {
setLoading(false)
}
})
registry
.register(AppDebugPlayground)
.register(AppDashboardSettings)
.register(AppUserProfile)
.register(AppOverview)
.register(AppKeyViz)
.register(AppStatement)
.register(AppClusterInfo)
.register(AppDiagnose)
.register(AppSearchLogs)
.register(AppInstanceProfiling)
.register(AppSlowQuery)
if (routing.isLocationMatch('/')) {
singleSpa.navigateToUrl('#' + registry.getDefaultRouter())
}
window.addEventListener('single-spa:app-change', () => {
const spinner = document.getElementById('dashboard_page_spinner')
if (spinner) {
spinner.remove()
}
if (!routing.isSignInPage()) {
if (!auth.getAuthTokenAsBearer()) {
singleSpa.navigateToUrl('#' + routing.signInRoute)
}
}
})
window.addEventListener('single-spa:before-routing-event', () => {})
window.addEventListener('single-spa:app-change', () => {
const spinner = document.getElementById('dashboard_page_spinner')
if (spinner) {
spinner.remove()
}
if (!routing.isSignInPage()) {
if (!auth.getAuthTokenAsBearer()) {
singleSpa.navigateToUrl('#' + routing.signInRoute)
}
}
})