add sso error to model api

This commit is contained in:
Simon Larsen
2023-03-06 19:15:51 +00:00
parent e601ba0928
commit 508f67c413
5 changed files with 31 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ enum ExceptionCode {
PaymentRequiredException = 402,
NotFoundException = 404,
TimeoutException = 408,
SsoAuthorizationException = 406,
}
export default ExceptionCode;

View File

@@ -4,7 +4,7 @@ import ExceptionCode from './ExceptionCode';
export default class NotAuthorizedException extends Exception {
public constructor() {
super(
ExceptionCode.NotAuthorizedException,
ExceptionCode.SsoAuthorizationException,
'SSO Authorization Required'
);
}

View File

@@ -97,6 +97,7 @@ class BaseAPI extends API {
protected static override handleError(
error: HTTPErrorResponse | APIException
): HTTPErrorResponse | APIException {
if (error instanceof HTTPErrorResponse && error.statusCode === 401) {
const cookies: Cookies = new Cookies();
cookies.remove('admin-data', { path: '/' });

View File

@@ -19,6 +19,7 @@ import Sort from './Sort';
import Project from 'Model/Models/Project';
import Populate from './Populate';
import User from '../User';
import Navigation from '../Navigation';
export interface ListResult<TBaseModel extends BaseModel> extends JSONObject {
data: Array<TBaseModel>;
@@ -106,6 +107,9 @@ export default class ModelAPI {
if (result.isSuccess()) {
return result;
}
this.checkStatusCode(result);
throw result;
}
@@ -158,6 +162,9 @@ export default class ModelAPI {
if (result.isSuccess()) {
return result;
}
this.checkStatusCode(result);
throw result;
}
@@ -227,6 +234,10 @@ export default class ModelAPI {
limit: result.limit,
};
}
this.checkStatusCode(result);
throw result;
}
@@ -275,6 +286,8 @@ export default class ModelAPI {
return count;
}
this.checkStatusCode(result);
throw result;
}
@@ -346,6 +359,9 @@ export default class ModelAPI {
if (result.isSuccess()) {
return result.data as TBaseModel;
}
this.checkStatusCode(result);
throw result;
}
@@ -383,6 +399,18 @@ export default class ModelAPI {
return;
}
this.checkStatusCode(result);
throw result;
}
private static checkStatusCode<TBaseModel extends BaseModel>(result: HTTPResponse<TBaseModel | JSONObject | JSONArray | Array<TBaseModel>> | HTTPErrorResponse){
if(result.statusCode === 406){
const project: Project | null = ProjectUtil.getCurrentProject();
if(project && project.id){
Navigation.navigate(new Route(`/dashboard/${project._id}/sso`));
}
}
}
}

View File

@@ -109,8 +109,6 @@ import MonitorIncidents from './Pages/Monitor/View/Incidents';
import MonitorInoperational from './Pages/Monitor/NotOperationalMonitors';
import MonitorViewCustomFields from './Pages/Monitor/View/CustomFields';
// Import CSS
// import 'CommonUI/src/Styles/theme.scss';
import User from 'CommonUI/src/Utils/User';
import Logout from './Pages/Logout/Logout';
import ModelAPI, { ListResult } from 'CommonUI/src/Utils/ModelAPI/ModelAPI';