Skip to content

Commit

Permalink
handle http response 403 forbiden error (feathr-ai#522)
Browse files Browse the repository at this point in the history
- Add interceptors for 'Axios' to handle error responses 403 automatically
- Navigate to error page with message details when receiving 403 forbidden response
  • Loading branch information
enya-yx authored and ahlag committed Aug 26, 2022
1 parent aba29dd commit 39758d7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ui/src/api/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,25 @@ export const getIdToken = async (

export const authAxios = async (msalInstance: PublicClientApplication) => {
const token = await getIdToken(msalInstance);
return Axios.create({
const axios = Axios.create({
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
baseURL: getApiBaseUrl(),
});

axios.interceptors.response.use(
(response) => {
return response;
},
(error) => {
if (error.response?.status === 403) {
const detail = error.response.data.detail;
window.location.href = "/responseErrors/403/" + detail;
}
//TODO: handle other response errors
}
);
return axios;
};
5 changes: 5 additions & 0 deletions ui/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Jobs from "./pages/jobs/jobs";
import Monitoring from "./pages/monitoring/monitoring";
import LineageGraph from "./pages/feature/lineageGraph";
import Management from "./pages/management/management";
import ResponseErrors from "./pages/responseErrors/responseErrors";
import RoleManagement from "./pages/management/roleManagement";
import { getMsalConfig } from "./utils/utils";

Expand Down Expand Up @@ -48,6 +49,10 @@ const App: React.FC = () => {
<Route path="/monitoring" element={<Monitoring />} />
<Route path="/management" element={<Management />} />
<Route path="/role-management" element={<RoleManagement />} />
<Route
path="/responseErrors/:status/:detail"
element={<ResponseErrors />}
/>
</Routes>
</Layout>
</Layout>
Expand Down
31 changes: 31 additions & 0 deletions ui/src/pages/responseErrors/responseErrors.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Card, Typography } from "antd";
import { useParams } from "react-router-dom";

const { Title } = Typography;

const ResponseErrors: React.FC = () => {
const { status, detail } = useParams();
switch (status) {
case "403":
return (
<div className="page">
<Card style={{ minWidth: "1000px" }}>
<Title level={3}> ERROR 403</Title>
ACCESS NOT GRANTED
<Card>{detail}</Card>
</Card>
</div>
);

default:
return (
<div className="page">
<Card style={{ minWidth: "1000px" }}>
<Title level={3}>Unknown Error</Title>
</Card>
</div>
);
}
};

export default ResponseErrors;

0 comments on commit 39758d7

Please sign in to comment.