next-drupal icon indicating copy to clipboard operation
next-drupal copied to clipboard

Issue 687: Throw error when backend error in /router/translate-path

Open marcorcau opened this issue 1 year ago • 1 comments

to avoid re-generation with 404.

This pull request is for: (mark with an "x")

  • [ ] examples/*
  • [ ] modules/next
  • [x] packages/next-drupal
  • [ ] starters/basic-starter
  • [ ] starters/graphql-starter
  • [ ] Other

GitHub Issue: #687

  • [ ] I need help adding tests. (mark with an "x")

Describe your changes

When /router/translate-path?path=xxx response is "Internal server error" (starts with "5") throw Error instead of returning the same as if it was 404 Not Found to avoid re-generation with 404.

marcorcau avatar Feb 19 '24 22:02 marcorcau

Someone is attempting to deploy a commit to the Chapter Three Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Feb 19 '24 22:02 vercel[bot]

I just noticed that getResourceByPath() and its tests will also need to be updated for this bug.

JohnAlbin avatar Apr 13 '24 04:04 JohnAlbin

I just noticed that getResourceByPath() and its tests will also need to be updated for this bug.

I've added this to the MR and also a test for it, but now there is a bit of code duplication:

      let errorMessage: string
      try {
        const responseJson = await response.json()
        errorMessage = `${response.status} ${responseJson?.message}`
      } catch (e) {
        /* c8 ignore next 2 */
        errorMessage = `${response.status} ${response.statusText}`
      }
      throw new Error(errorMessage)

Should I refactor that in a common function or wejust accept it?

marcorcau avatar Apr 14 '24 12:04 marcorcau

Looking at this more, I realize that the fix is a lot more complicated then "just update getResourceByPath()".

I've taken the code from the PR and added to it to make a new PR. #743

Thanks for reporting this bug and thanks for all your effort in fixing it, @marcorcau!

JohnAlbin avatar Apr 19 '24 17:04 JohnAlbin