-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
qol(endpoints): helpful error message when a response is not provided #10455
Conversation
🦋 Changeset detectedLatest commit: bf2d6b7 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
||
if (!response || response instanceof Response === false) { | ||
throw new AstroError(EndpointDidNotReturnAResponse) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this handled by the renderPage
function of the pipeline? If not, then a test should be cover this edge case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The renderPage
function wouldn't run for endpoints. I'm guessing you meant RenderContext.render()
- it checks the return of the middleware. Failures from the absence of a response occur before control flow returns to it.
An error here is not new, it was just thrown by accessing response.status
before, now it thrown explicitly. A test would work the same before and after this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test would work the same before and after this PR.
Now we throw an astro error, we can assert that the correct error is thrown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A different new error would be logged, but the tests will have access to a 500 response either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, I believe it's worth expanding our test suite in this case. Any throw
could return a 500, although this is a specific error that Astro decides to handle in a meaningful way with a proper message.
Such cases should to be tested. We do this in our middleware, I don't see any reason why we shouldn't do the same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that makes sense. I had thought you meant a regression test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the text looks great by docs! 🙌
Changes
cant read status of undefined
(we do a check onresponse.status
)Testing
Docs