Skip to content

Commit

Permalink
Merge pull request #1385 from terrestris/unauthorized-error
Browse files Browse the repository at this point in the history
Show permission denied message for applications that are not public
  • Loading branch information
ahennr authored Dec 20, 2023
2 parents 28e6f59 + 069174b commit 3052e59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {

import {
Alert,
AlertProps,
ConfigProvider,
notification
} from 'antd';
Expand Down Expand Up @@ -123,8 +124,9 @@ export interface ThemeProperties extends React.CSSProperties {
// eslint-disable-next-line no-shadow
enum LoadingErrorCode {
APP_ID_NOT_SET = 'APP_ID_NOT_SET',
APP_CONFIG_NOT_FOUND = 'APP_CONFIG_NOT_FOUND'
};
APP_CONFIG_NOT_FOUND = 'APP_CONFIG_NOT_FOUND',
APP_UNAUTHORIZED = 'APP_UNAUTHORIZED'
}

const client = new SHOGunAPIClient({
url: ClientConfiguration.shogunBase || '/'
Expand Down Expand Up @@ -155,6 +157,9 @@ const getApplicationConfiguration = async (applicationId: number) => {

return application;
} catch (error) {
if ((error as Error).message.indexOf('401') > -1) {
throw new Error(LoadingErrorCode.APP_UNAUTHORIZED);
}
Logger.error(`Error while loading application with ID ${applicationId}: ${error}`);
}
};
Expand Down Expand Up @@ -699,12 +704,18 @@ const renderApp = async () => {
await i18n.init(initOpts);
}

let type: AlertProps['type'] = 'warning';
let errorDescription = i18n.t('Index.errorDescription');

if ((error as Error)?.message === LoadingErrorCode.APP_ID_NOT_SET) {
errorDescription = i18n.t('Index.errorDescriptionAppIdNotSet');
}

if ((error as Error)?.message === LoadingErrorCode.APP_UNAUTHORIZED) {
errorDescription = i18n.t('Index.permissionDeniedUnauthorized');
type = 'error';
}

if ((error as Error)?.message === LoadingErrorCode.APP_CONFIG_NOT_FOUND) {
const appId = UrlUtil.getQueryParam(window.location.href, 'applicationId');

Expand All @@ -719,7 +730,7 @@ const renderApp = async () => {
className="error-boundary"
message={i18n.t('Index.errorMessage')}
description={errorDescription}
type="warning"
type={type}
showIcon
/>
</React.StrictMode>,
Expand Down
8 changes: 5 additions & 3 deletions src/i18n/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export default {
errorMessage: 'Fehler beim Laden der Applikation',
errorDescription: 'Aufgrund eines unerwarteten Fehlers konnte die Applikation nicht geladen werden.',
errorDescriptionAppIdNotSet: 'Keine Applikations-ID angegeben. Bitte geben Sie die ID als Abfrageparameter an, z.B. ?applicationId=1909',
errorDescriptionAppConfigNotFound: 'Die Applikation mit der ID {{applicationId}} konnte nicht geladen werden.'
errorDescriptionAppConfigNotFound: 'Die Applikation mit der ID {{applicationId}} konnte nicht geladen werden.',
permissionDeniedUnauthorized: 'Dies ist keine öffentliche Applikation. Anmeldung erforderlich.'
},
Nominatim: {
placeholder: 'Ortsname, Straßenname, Stadtteilname, POI usw.'
Expand Down Expand Up @@ -386,9 +387,10 @@ export default {
applicationLoadErrorDescription: 'The application with ID {{applicationId}} could not be loaded correctly. ' +
'You\'re seeing the default application configuration.',
errorMessage: 'Error while loading the application',
errorDescription: 'An unexpected error occured while loading the application.',
errorDescription: 'An unexpected error occurred while loading the application.',
errorDescriptionAppIdNotSet: 'No application ID given. Please provide the ID as query parameter, e.g. ?applicationId=1909',
errorDescriptionAppConfigNotFound: 'The application with ID {{applicationId}} could not be loaded correctly.'
errorDescriptionAppConfigNotFound: 'The application with ID {{applicationId}} could not be loaded correctly.',
permissionDeniedUnauthorized: 'This application is not public. Authentication required.'
},
Nominatim: {
placeholder: 'Place name, street name, district name, POI, etc.'
Expand Down

0 comments on commit 3052e59

Please sign in to comment.