Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Ensure API route errors are propagated in minimal mode (vercel#26875)
Browse files Browse the repository at this point in the history
This ensures when an error occurs in an API route while using minimal mode the error is bubbled so it can be handled at the top-level 

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
  • Loading branch information
ijjk authored Jul 2, 2021
1 parent 3535437 commit 5dc1cbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ export default class Server {
query,
pageModule,
this.renderOpts.previewProps,
false
this.minimalMode
)
return true
}
Expand Down
3 changes: 3 additions & 0 deletions test/integration/required-server-files/pages/api/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default async function handler(req, res) {
throw new Error('some error from /api/error')
}
9 changes: 9 additions & 0 deletions test/integration/required-server-files/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ describe('Required Server Files', () => {
expect(errors[0].message).toContain('gsp hit an oops')
})

it('should bubble error correctly for API page', async () => {
errors = []
const res = await fetchViaHTTP(appPort, '/api/error')
expect(res.status).toBe(500)
expect(await res.text()).toBe('error')
expect(errors.length).toBe(1)
expect(errors[0].message).toContain('some error from /api/error')
})

it('should normalize optional values correctly for SSP page', async () => {
const res = await fetchViaHTTP(
appPort,
Expand Down

0 comments on commit 5dc1cbd

Please sign in to comment.