Skip to content

Commit

Permalink
Fix: types error for Nutlope#18
Browse files Browse the repository at this point in the history
  • Loading branch information
mwelwankuta committed Feb 4, 2023
1 parent 09c03d4 commit 85e2524
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pages/api/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ const ratelimit = redis
})
: undefined;

const endpointResponse = (restoredImage: string | null, endpointSuccess: EndPointSuccess) => {
function endpointResponse<ResponseType>(restoredImage: string | null , endpointSuccess: EndPointSuccess) {
const {pass, fail} = endpointSuccess;
if (restoredImage) {
return pass;
return pass as ResponseType;
}
return fail;
return fail as ResponseType;
}

export default async function handler(
Expand Down Expand Up @@ -91,8 +91,8 @@ export default async function handler(
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
const status = endpointResponse(restoredImage, {pass: 200, fail: 500})
const json = endpointResponse(restoredImage, {pass: restoredImage, fail: "Failed to restore image"})
const status = endpointResponse<number>(restoredImage, {pass: 200, fail: 500});
const json = endpointResponse<string>(restoredImage, {pass: restoredImage, fail: "Failed to restore image"});
res
.status(status)
.json(json);
Expand Down

0 comments on commit 85e2524

Please sign in to comment.