While working on my function, I encountered an error message in Typescript specifically pointing to the second last line:
The error stated that 'organizationInfoResponse' is being used before it is assigned.
I'm unsure about how to address this issue since I am assigning 'organizationInfoResponse' within a try-catch block while making a fetch call. Can you provide some guidance on resolving this situation?
interface OrganizationInfoResponse {
organization_name: string;
organization_id: string;
errorCode?: string;
}
export const handleGetOrganization = async (
organizationName: string,
): Promise<OrganizationInfoResponse> => {
let organizationInfoResponse: OrganizationInfoResponse;
try {
const rawRes = await fetch(
`/sometestendpoint/${organizationName}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
},
);
organizationInfoResponse = await rawRes.json();
if (rawRes.status >= 400) {
if (organizationInfoResponse.errorCode === ErrorCodes.INVALID_ORG_NAME) {
throw new Error('Given Organization Name is invalid');
}
}
} catch (error) {
// Do something
}
return organizationInfoResponse;
};