Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle http response 403 forbiden error #522

Merged
merged 1 commit into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -14,6 +14,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 @@ -46,6 +47,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"
enya-yx marked this conversation as resolved.
Show resolved Hide resolved
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;