Skip to content

Unable to fetch from /api/issues/:number #1

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

Closed
FranciscoKloganB opened this issue Aug 28, 2022 · 0 comments
Closed

Unable to fetch from /api/issues/:number #1

FranciscoKloganB opened this issue Aug 28, 2022 · 0 comments

Comments

@FranciscoKloganB
Copy link

FranciscoKloganB commented Aug 28, 2022

Edit: Found the error. I was passing the issue id to the request instead of the issue number.

MSW Worker always responds with 404 regardless of the searched issue with the body {"message":"Not found"}. My query code is below.

import { IssueStatus } from "@enums"
import { useQuery } from "react-query"

const toDomainIssue = (dto: IssueDto): Issue => ({ labelIDs: dto.labels, ...dto })

export function useIssue(number: string) {
  const keys = ["issues", number]

  function fetcher({ queryKey }: { queryKey: typeof keys }): Promise<Issue> {
    const [, number] = queryKey

    return fetch(`/api/issues/${number}`)
      .then((res) => res.json())
      .then((dto) => toDomainIssue(dto))
  }

  return useQuery(keys, fetcher)
}

Compared with the screenshot below taken from the video course, the endpoint to where I am requesting does not appear incorrect. Impossible to progress on the course unless this is fixed.

image
image
image

@FranciscoKloganB FranciscoKloganB changed the title [ Unable to fetch from /api/issues/:number Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant