Skip to content
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

Merged
merged 3 commits into from
Mar 18, 2024

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Mar 15, 2024

Changes

  • From a bad experience in a support thread.
  • Misuse of endpoints results in cant read status of undefined (we do a check on response.status)

Testing

  • Does not affect behavior.

Docs

  • The error will show up in error reference on docs.

Copy link

changeset-bot bot commented Mar 15, 2024

🦋 Changeset detected

Latest 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

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Mar 15, 2024
Comment on lines +54 to +57

if (!response || response instanceof Response === false) {
throw new AstroError(EndpointDidNotReturnAResponse)
}
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

@lilnasy lilnasy Mar 15, 2024

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.

Copy link
Member

@ematipico ematipico Mar 18, 2024

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.

Copy link
Contributor Author

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.

Copy link
Member

@Princesseuh Princesseuh left a 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!

Copy link
Member

@sarah11918 sarah11918 left a 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! 🙌

@lilnasy lilnasy merged commit c126661 into withastro:main Mar 18, 2024
13 checks passed
@lilnasy lilnasy deleted the endpoint-error branch March 18, 2024 14:36
@astrobot-houston astrobot-houston mentioned this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants