mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
add sso error to model api
This commit is contained in:
@@ -12,6 +12,7 @@ enum ExceptionCode {
|
||||
PaymentRequiredException = 402,
|
||||
NotFoundException = 404,
|
||||
TimeoutException = 408,
|
||||
SsoAuthorizationException = 406,
|
||||
}
|
||||
|
||||
export default ExceptionCode;
|
||||
|
||||
@@ -4,7 +4,7 @@ import ExceptionCode from './ExceptionCode';
|
||||
export default class NotAuthorizedException extends Exception {
|
||||
public constructor() {
|
||||
super(
|
||||
ExceptionCode.NotAuthorizedException,
|
||||
ExceptionCode.SsoAuthorizationException,
|
||||
'SSO Authorization Required'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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: '/' });
|
||||
|
||||
@@ -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`));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user