Using Typescript and Axios implement a function getGithubIssue(owner:string,…
- User
Using Typescript and Axios implement a function
getGithubIssue(owner:string, repo:string, number:number):GithubIssue | null.It only needs to return the fields number, title, body.
The values passed in may be unsanitized
We should return
nullon a 404. A valid value on 200 throw on anything else Assistant
Here is an implementation of the getGithubIssue function:
import axios from 'axios'; interface GithubIssue { number: number; title: string; body: string; } async function getGithubIssue(owner: string, repo: string, number: number): Promise<GithubIssue | null> { try { const result = await axios.get<GithubIssue>( `https://api.github.com/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/issues/${number}` ); if (result.status === 200) { return { number: result.data.number, title: result.data.title, body: result.data.body }; } else if (result.status === 404) { return null; } else { throw new Error('Unexpected status code'); } } catch (error) { if (axios.isAxiosError(error) && error.response?.status === 404) { return null; } else { throw error; } } } export { getGithubIssue };
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.