Skip to content

Commit

Permalink
Merge pull request #957 from Code4GovTech/bugfix/api-error-response
Browse files Browse the repository at this point in the history
Error  Response Changes
  • Loading branch information
riya-2206 authored Jun 14, 2024
2 parents fc333fb + 0712cf9 commit 1e5e97a
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 38 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"clsx": "^1.1.1",
"docusaurus": "^1.14.7",
"file-loader": "^6.2.0",
"markdown-to-jsx": "^7.4.7",
"prism-react-renderer": "^1.2.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand Down
1 change: 0 additions & 1 deletion src/components/C4GT2024Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ function C4GT2024Page() {
<li className="breadcrumbs__item breadcrumbs__item--active">
<a
className="breadcrumbs__link breadcrumbs-items"
href="/docs/2024/"
style={{ cursor: "pointer" }}
>
C4GT'24
Expand Down
46 changes: 35 additions & 11 deletions src/components/ProjectDescription.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,44 @@ import useParseMarkdown from "../hooks/useParseMarkdown";

function ProjectDescription({
currentIssue,
currentIssueData,
setCurrentTab,
setSelectedProject,
setIssueNumber,
error,
setError
issueData
}) {
const history = useHistory();
const {API_AUTH_KEY,API_BASE_URL} = useParseMarkdown();
const [description, setDescription] = useState(null);
const [mobile, setMobile] = useState(false);
const [error,setError] =useState(null)
const [currentIssueData,setCurrentIssueData] = useState(null)

useEffect(() => {
setError(()=>null);
setCurrentIssueData(()=>{
let data = issueData?.filter((d,i)=>{
if(d.org_name===currentIssue) return d.issues
else return null
})
return data
})
fetch(`${API_BASE_URL}/issues/${currentIssue}`, {
method: "GET",
headers: {
"X-Secret-Key": API_AUTH_KEY,
},
})
.then((response) => {
if (!response.ok) {
throw new Error(`Error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
setDescription(() => data);
if(data?.message){
throw new Error(`${data?.message}`);
}
else if(data?.error){
throw new Error(`${data?.error}`);
}
else setDescription(() => data);
})
.catch((error) => {
setError(error);
Expand All @@ -56,7 +66,20 @@ function ProjectDescription({
}, []);
return (
<>
{!error && (
{error ? (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
width: "100%",
height: "100vh",
flexDirection: "column",
}}
>
<h3>{error.message}</h3>
</div>
) : description ? (
<div
className="container padding-top--md padding-bottom--lg"
style={{ minHeight: "60vh" }}
Expand Down Expand Up @@ -103,10 +126,11 @@ function ProjectDescription({
</h3>
{currentIssueData?.length != 0 && (
<ul>
{currentIssueData?.map((d, i) => {
{currentIssueData?.[0]?.issues?.map((d, i) => {
// console.log(currentIssueData)
return (
<li key={i}>
<a
<a style={{cursor:"pointer"}}
onClick={() => {
const newUrl = `/docs/2024/org?id=${currentIssue}&issue=${d.name}`;
history.push(newUrl);
Expand All @@ -130,7 +154,7 @@ function ProjectDescription({
</div>
</div>
</div>
)}
):<></>}
</>
);
}
Expand Down
29 changes: 23 additions & 6 deletions src/components/SubDescription.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect, useState } from "react";
import useParseMarkdown from "../hooks/useParseMarkdown";

function SubProjectDescription({ selectedProject, issueNumber, currentIssue,error,setError }) {
function SubProjectDescription({ selectedProject, issueNumber, currentIssue }) {
const {weeklyGoals, weeklyLearnings,API_AUTH_KEY,API_BASE_URL} = useParseMarkdown();
const [description, setDescription] = useState(null);
const [error,setError] =useState(null)

useEffect(() => {
setError(()=>null);
Expand All @@ -14,21 +15,37 @@ function SubProjectDescription({ selectedProject, issueNumber, currentIssue,erro
},
})
.then((response) => {
if (!response.ok) {
throw new Error(`Error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
setDescription(() => data);
if(data?.message){
throw new Error(`${data?.message}`);
}
else if(data?.error){
throw new Error(`${data?.error}`);
}
else setDescription(() => data);
})
.catch((error) => {
setError(()=>error)
});
}, [selectedProject]);

return (<>
{!error && <div
{error ? (
<div
style={{
display: "flex",
justifyContent: "center",
alignItems: "center",
width: "100%",
height: "100vh",
flexDirection: "column",
}}
>
<h3>{error.message}</h3>
</div>
) : <div
className="container padding-top--md padding-bottom--lg"
style={{ minHeight: "60vh" }}
>
Expand Down
15 changes: 9 additions & 6 deletions src/pages/docs/2024/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ function C4GT2024() {
},
})
.then((response) => {
if (!response.ok) {
throw new Error(`Error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
setIssueData(() => data);
if(data?.message){
throw new Error(`${data?.message}`);
}
else if(data?.error){
throw new Error(`${data?.error}`);
}
else setIssueData(() => data);
})
.catch((error) => {
setError(() => error);
Expand All @@ -43,8 +46,8 @@ function C4GT2024() {
height: "100vh",
flexDirection: "column",
}}
><h3>Oops, something went wrong</h3>
<p>{error.message}</p>
>
<h3>{error.message}</h3>
</div>
) : (
<Layout>
Expand Down
25 changes: 11 additions & 14 deletions src/pages/docs/2024/org/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ function C4GT2024() {
const {API_AUTH_KEY,API_BASE_URL} = useParseMarkdown();
const [currentTab, setCurrentTab] = useState("description");
const [currentIssue, setCurrentIssue] = useState(null);
const [currentIssueData, setCurrentIssueData] = useState(null);
const [issueData, setIssueData] = useState(null);
const [selectedProject, setSelectedProject] = useState(null);
const [issueNumber, setIssueNumber] = useState(null);
const [error, setError] = useState(null);

useEffect(() => {
setError(()=>null);
const queryString = location.search;
const urlParams = new URLSearchParams(queryString);
const product = urlParams.get("id") ? urlParams.get("id") : "c4gt";
Expand All @@ -29,21 +29,23 @@ function C4GT2024() {
const newUrl = `/docs/2024/org?id=${product}`;
history.push(newUrl);
setCurrentIssue(() => product);
setError(()=>null);
fetch(`${API_BASE_URL}/issues`, {
method: "GET",
headers: {
"X-Secret-Key": API_AUTH_KEY,
},
})
.then((response) => {
if (!response.ok) {
throw new Error(`Error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
setIssueData(() => data);
if(data?.message){
throw new Error(`${data?.message}`);
}
else if(data?.error){
throw new Error(`${data?.error}`);
}
else setIssueData(() => data);
})
.catch((error) => {
setError(()=>error);
Expand All @@ -68,8 +70,8 @@ function C4GT2024() {
height: "100vh",
flexDirection: "column",
}}
><h3>Oops, something went wrong</h3>
<p>{error.message}</p>
>
<h3>{error.message}</h3>
</div>
) : (
<Layout>
Expand Down Expand Up @@ -106,7 +108,6 @@ function C4GT2024() {
setSelectedProject(() => null);
setIssueNumber(() => null);
setCurrentTab(() => "description");
setCurrentIssueData(() => data?.issues);
}}
>
<div
Expand Down Expand Up @@ -170,12 +171,10 @@ function C4GT2024() {
{currentTab == "description" && currentIssue != null ? (
<ProjectDescription
currentIssue={currentIssue}
currentIssueData={currentIssueData}
setCurrentTab={setCurrentTab}
setIssueNumber={setIssueNumber}
setSelectedProject={setSelectedProject}
error={error}
setError={setError}
issueData={issueData}
/>
) : (
<></>
Expand All @@ -185,8 +184,6 @@ function C4GT2024() {
selectedProject={selectedProject}
issueNumber={issueNumber}
currentIssue={currentIssue}
error={error}
setError={setError}
/>
) : (
<></>
Expand Down

0 comments on commit 1e5e97a

Please sign in to comment.