Skip to content

Commit b1179a5

Browse files
authored
openshift error for internal server error (#1436)
1 parent 0d8ad6b commit b1179a5

File tree

13 files changed

+65
-111
lines changed

13 files changed

+65
-111
lines changed

epictrack-api/src/api/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from flask import Flask, current_app
2424
from flask_restx import abort
2525
from marshmallow import ValidationError
26+
from werkzeug.exceptions import HTTPException
2627

2728
from api import config
2829
from api.config import _Config
@@ -68,16 +69,16 @@ def add_version(response): # pylint: disable=unused-variable
6869
@app.errorhandler(Exception)
6970
def handle_error(err):
7071
current_app.logger.error(str(err))
71-
if isinstance(err, ValidationError):
72-
return err.messages, HTTPStatus.BAD_REQUEST
73-
if isinstance(err, ResourceExistsError):
74-
return err.message, HTTPStatus.CONFLICT
75-
if isinstance(err, ResourceNotFoundError):
76-
return err.message, HTTPStatus.NOT_FOUND
77-
if isinstance(err, PermissionDeniedError):
78-
return err.message, HTTPStatus.FORBIDDEN
79-
if isinstance(err, UnprocessableEntityError):
80-
return err.message, HTTPStatus.UNPROCESSABLE_ENTITY
72+
# if isinstance(err, ValidationError):
73+
# return err.messages, HTTPStatus.BAD_REQUEST
74+
# if isinstance(err, ResourceExistsError):
75+
# return err.message, HTTPStatus.CONFLICT
76+
# if isinstance(err, ResourceNotFoundError):
77+
# return err.message, HTTPStatus.NOT_FOUND
78+
# if isinstance(err, PermissionDeniedError):
79+
# return err.message, HTTPStatus.FORBIDDEN
80+
# if isinstance(err, UnprocessableEntityError):
81+
# return err.message, HTTPStatus.UNPROCESSABLE_ENTITY
8182
# if run_mode == "development":
8283
# # To get stacktrace in local development for internal server errors
8384
# raise err

epictrack-api/src/api/exceptions/__init__.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
error - a description of the error {code / description: classname / full text}
2020
status_code - where possible use HTTP Error Codes
2121
"""
22+
from werkzeug.exceptions import UnprocessableEntity, Forbidden, NotFound, BadRequest, Conflict
23+
from werkzeug.wrappers.response import Response
2224

2325

2426
class BusinessError(Exception):
@@ -31,46 +33,51 @@ def __init__(self, error, status_code, *args, **kwargs):
3133
self.status_code = status_code
3234

3335

34-
class ResourceExistsError(Exception):
36+
class ResourceExistsError(Conflict):
3537
"""Exception raised when a duplicate resource exists."""
3638

3739
def __init__(self, message, *args, **kwargs):
3840
"""Return a valid ResourceExistsError."""
3941
super().__init__(*args, **kwargs)
40-
self.message = message
42+
self.description = message
43+
self.response = Response(message, status=409)
4144

4245

43-
class BadRequestError(Exception):
46+
class BadRequestError(BadRequest):
4447
"""Exception raised when there are issues with the api input"""
4548

4649
def __init__(self, message, *args, **kwargs):
4750
"""Return a valid BadRequestError."""
4851
super().__init__(*args, **kwargs)
49-
self.message = message
52+
self.description = message
53+
self.response = Response(message, status=400)
5054

5155

52-
class ResourceNotFoundError(Exception):
56+
class ResourceNotFoundError(NotFound):
5357
"""Exception raised when resource not found"""
5458

5559
def __init__(self, message, *args, **kwargs):
5660
"""Return a valid ResourceExistsError."""
5761
super().__init__(*args, **kwargs)
58-
self.message = message
62+
self.description = message
63+
self.response = Response(message, status=404)
5964

6065

61-
class PermissionDeniedError(Exception):
66+
class PermissionDeniedError(Forbidden):
6267
"""Exception raised when resource not found"""
6368

6469
def __init__(self, message, *args, **kwargs):
6570
"""Return a valid ResourceExistsError."""
6671
super().__init__(*args, **kwargs)
67-
self.message = message
72+
self.description = message
73+
self.response = Response(message, status=403)
6874

6975

70-
class UnprocessableEntityError(Exception):
76+
class UnprocessableEntityError(UnprocessableEntity):
7177
"""Exception raised when resource is not processable"""
7278

7379
def __init__(self, message, *args, **kwargs):
7480
"""Return a valid UnprocessableEntityError."""
7581
super().__init__(*args, **kwargs)
76-
self.message = message
82+
self.description = message
83+
self.response = Response(message, status=422)

epictrack-web/src/@types/global.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export {}
1+
export {};
22

33
declare global {
44
interface Array<T> {
55
findLastIndex(
66
predicate: (value: T, index: number, obj: T[]) => unknown,
77
thisArg?: any
8-
): number
8+
): number;
99
}
1010
}

epictrack-web/src/components/shared/MasterContext.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import ServiceBase from "../../services/common/serviceBase";
44
import TrackDialog from "./TrackDialog";
55
import { SxProps } from "@mui/material";
66
import { showNotification } from "./notificationProvider";
7-
import { COMMON_ERROR_MESSAGE } from "../../constants/application-constant";
8-
import { getAxiosError } from "../../utils/axiosUtils";
7+
import { getErrorMessage } from "../../utils/axiosUtils";
98

109
interface MasterContextProps {
1110
// error: string | undefined;
@@ -146,11 +145,7 @@ export const MasterProvider = ({
146145
setShowModalForm(false);
147146
getData();
148147
} catch (e) {
149-
const error = getAxiosError(e);
150-
const message =
151-
error?.response?.status === 422
152-
? error.response.data?.toString()
153-
: COMMON_ERROR_MESSAGE;
148+
const message = getErrorMessage(e);
154149
showNotification(message, {
155150
type: "error",
156151
});

epictrack-web/src/components/task/template/TemplateForm.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import { ListType } from "../../../models/code";
1313
import ControlledSelectV2 from "../../shared/controlledInputComponents/ControlledSelectV2";
1414
import TrackDialog from "../../shared/TrackDialog";
1515
import { showNotification } from "../../shared/notificationProvider";
16-
import { getAxiosError } from "../../../utils/axiosUtils";
17-
import { COMMON_ERROR_MESSAGE } from "../../../constants/application-constant";
1816
import templateService from "../../../services/taskService/templateService";
17+
import { getErrorMessage } from "../../../utils/axiosUtils";
1918

2019
export default function TemplateForm({ ...props }) {
2120
const [eaActs, setEAActs] = React.useState<ListType[]>([]);
@@ -99,11 +98,7 @@ export default function TemplateForm({ ...props }) {
9998
}
10099
reset();
101100
} catch (e) {
102-
const error = getAxiosError(e);
103-
const message =
104-
error?.response?.status === 422
105-
? error.response.data?.toString()
106-
: COMMON_ERROR_MESSAGE;
101+
const message = getErrorMessage(e);
107102
showNotification(message, {
108103
type: "error",
109104
});

epictrack-web/src/components/workPlan/event/EventForm.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import ControlledSelectV2 from "../../shared/controlledInputComponents/Controlle
1818
import { Palette } from "../../../styles/theme";
1919
import { WorkplanContext } from "../WorkPlanContext";
2020
import { showNotification } from "../../shared/notificationProvider";
21-
import { getAxiosError } from "../../../utils/axiosUtils";
21+
import { getErrorMessage } from "../../../utils/axiosUtils";
2222
import { ListType } from "../../../models/code";
2323
import RichTextEditor from "../../shared/richTextEditor";
2424
import eventService from "../../../services/eventService/eventService";
@@ -371,11 +371,7 @@ const EventForm = ({
371371
handleSaveEvent(submittedData);
372372
}
373373
} catch (e: any) {
374-
const error = getAxiosError(e);
375-
const message =
376-
error?.response?.status === 422
377-
? error.response.data?.toString()
378-
: COMMON_ERROR_MESSAGE;
374+
const message = getErrorMessage(e);
379375
showNotification(message, {
380376
type: "error",
381377
});
@@ -463,11 +459,7 @@ const EventForm = ({
463459
setDateCheckStatus(undefined);
464460
}
465461
} catch (e) {
466-
const error = getAxiosError(e);
467-
const message =
468-
error?.response?.status === 422
469-
? error.response.data?.toString()
470-
: COMMON_ERROR_MESSAGE;
462+
const message = getErrorMessage(e);
471463
showNotification(message, {
472464
type: "error",
473465
});

epictrack-web/src/components/workPlan/event/EventList.tsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ import {
3535
import taskEventService from "../../../services/taskEventService/taskEventService";
3636
import { showNotification } from "../../shared/notificationProvider";
3737
import ImportTaskEvent from "../task/ImportTaskEvent";
38-
import { getAxiosError } from "../../../utils/axiosUtils";
39-
import { COMMON_ERROR_MESSAGE } from "../../../constants/application-constant";
4038
import {
4139
TemplateStatus,
4240
Work,
@@ -54,6 +52,8 @@ import { When } from "react-if";
5452
import WarningBox from "../../shared/warningBox";
5553
import { useAppDispatch } from "../../../hooks";
5654
import { setLoadingState } from "../../../services/loadingService";
55+
import { getErrorMessage } from "../../../utils/axiosUtils";
56+
import { COMMON_ERROR_MESSAGE } from "../../../constants/application-constant";
5757

5858
const ImportFileIcon: React.FC<IconProps> = Icons["ImportFileIcon"];
5959
const DownloadIcon: React.FC<IconProps> = Icons["DownloadIcon"];
@@ -369,11 +369,7 @@ const EventList = () => {
369369
getTemplateUploadStatus();
370370
}
371371
} catch (e) {
372-
const error = getAxiosError(e);
373-
const message =
374-
error?.response?.status === 422
375-
? error.response.data?.toString()
376-
: COMMON_ERROR_MESSAGE;
372+
const message = getErrorMessage(e);
377373
showNotification(message, {
378374
type: "error",
379375
});
@@ -562,11 +558,7 @@ const EventList = () => {
562558
handleHighlightRows(highlightedRows);
563559
}
564560
} catch (e) {
565-
const error = getAxiosError(e);
566-
const message =
567-
error?.response?.status === 422
568-
? error.response.data?.toString()
569-
: COMMON_ERROR_MESSAGE;
561+
const message = getErrorMessage(e);
570562
showNotification(message, {
571563
type: "error",
572564
});
@@ -599,11 +591,7 @@ const EventList = () => {
599591
handleHighlightRows(highlightedRows);
600592
}
601593
} catch (e) {
602-
const error = getAxiosError(e);
603-
const message =
604-
error?.response?.status === 422
605-
? error.response.data?.toString()
606-
: COMMON_ERROR_MESSAGE;
594+
const message = getErrorMessage(e);
607595
showNotification(message, {
608596
type: "error",
609597
});
@@ -633,11 +621,7 @@ const EventList = () => {
633621
handleHighlightRows(highlightedRows);
634622
}
635623
} catch (e) {
636-
const error = getAxiosError(e);
637-
const message =
638-
error?.response?.status === 422
639-
? error.response.data?.toString()
640-
: COMMON_ERROR_MESSAGE;
624+
const message = getErrorMessage(e);
641625
showNotification(message, {
642626
type: "error",
643627
});

epictrack-web/src/components/workPlan/firstNations/FirstNationForm.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { FormControlLabel, Grid, TextField } from "@mui/material";
66
import { ETFormLabel } from "../../shared";
77
import ControlledSelectV2 from "../../shared/controlledInputComponents/ControlledSelectV2";
88
import { showNotification } from "../../shared/notificationProvider";
9-
import { COMMON_ERROR_MESSAGE } from "../../../constants/application-constant";
109
import indigenousNationService from "../../../services/indigenousNationService/indigenousNationService";
1110
import { sort } from "../../../utils";
1211
import workService from "../../../services/workService/workService";
1312
import ControlledSwitch from "../../shared/controlledInputComponents/ControlledSwitch";
1413
import { WorkplanContext } from "../WorkPlanContext";
15-
import { getAxiosError } from "../../../utils/axiosUtils";
1614
import { FirstNation, WorkFirstNation } from "../../../models/firstNation";
1715
import { OptionType } from "../../shared/filterSelect/type";
16+
import { getErrorMessage } from "../../../utils/axiosUtils";
17+
import { COMMON_ERROR_MESSAGE } from "../../../constants/application-constant";
1818

1919
interface FirstNationFormProps {
2020
workNationId?: number;
@@ -161,11 +161,7 @@ const FirstNationForm = ({ onSave, workNationId }: FirstNationFormProps) => {
161161
}
162162
}
163163
} catch (e: any) {
164-
const error = getAxiosError(e);
165-
const message =
166-
error?.response?.status === 422
167-
? error.response.data?.toString()
168-
: COMMON_ERROR_MESSAGE;
164+
const message = getErrorMessage(e);
169165
showNotification(message, {
170166
type: "error",
171167
});

epictrack-web/src/components/workPlan/firstNations/FirstNationList.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import { Palette } from "../../../styles/theme";
3535
import UserMenu from "../../shared/userMenu/UserMenu";
3636
import { Staff } from "../../../models/staff";
3737
import ImportFirstNation from "./ImportFirstNation";
38-
import { getAxiosError } from "../../../utils/axiosUtils";
3938
import projectService from "../../../services/projectService/projectService";
4039
import { Restricted } from "../../shared/restricted";
40+
import { getErrorMessage } from "../../../utils/axiosUtils";
4141

4242
const DownloadIcon: React.FC<IconProps> = Icons["DownloadIcon"];
4343
const ImportFileIcon: React.FC<IconProps> = Icons["ImportFileIcon"];
@@ -393,11 +393,7 @@ const FirstNationList = () => {
393393
getWorkFirstNations();
394394
}
395395
} catch (e) {
396-
const error = getAxiosError(e);
397-
const message =
398-
error?.response?.status === 422
399-
? error.response.data?.toString()
400-
: COMMON_ERROR_MESSAGE;
396+
const message = getErrorMessage(e);
401397
showNotification(message, {
402398
type: "error",
403399
});

epictrack-web/src/components/workPlan/status/StatusContext.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import TrackDialog from "../../shared/TrackDialog";
44
import StatusForm from "./StatusForm";
55
import { Status } from "../../../models/status";
66
import { showNotification } from "../../shared/notificationProvider";
7-
import { getAxiosError } from "../../../utils/axiosUtils";
8-
import { COMMON_ERROR_MESSAGE } from "../../../constants/application-constant";
97
import statusService from "../../../services/statusService/statusService";
108
import { useSearchParams } from "../../../hooks/SearchParams";
119
import { WorkplanContext } from "../WorkPlanContext";
10+
import { getErrorMessage } from "../../../utils/axiosUtils";
1211

1312
interface StatusContextProps {
1413
setShowStatusForm: Dispatch<SetStateAction<boolean>>;
@@ -99,11 +98,7 @@ export const StatusProvider = ({
9998
getWorkStatuses();
10099
setShowStatusForm(false);
101100
} catch (e) {
102-
const error = getAxiosError(e);
103-
const message =
104-
error?.response?.status === 422
105-
? error.response.data?.toString()
106-
: COMMON_ERROR_MESSAGE;
101+
const message = getErrorMessage(e);
107102
showNotification(message, {
108103
type: "error",
109104
});
@@ -124,11 +119,7 @@ export const StatusProvider = ({
124119
setStatus(undefined);
125120
getWorkStatuses();
126121
} catch (e) {
127-
const error = getAxiosError(e);
128-
const message =
129-
error?.response?.status === 422
130-
? error.response.data?.toString()
131-
: COMMON_ERROR_MESSAGE;
122+
const message = getErrorMessage(e);
132123
showNotification(message, {
133124
type: "error",
134125
});

0 commit comments

Comments
 (0)