Issue 687: Throw error when backend error in /router/translate-path
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.
Someone is attempting to deploy a commit to the Chapter Three Team on Vercel.
A member of the Team first needs to authorize it.
I just noticed that getResourceByPath() and its tests will also need to be updated for this bug.
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?
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!