Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
00179adc
Unverified
Commit
00179adc
authored
Jan 02, 2020
by
Joe Haddad
Committed by
GitHub
Jan 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix User Error in Async API Endpoint (#9911)
parent
d59858e3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
1 deletion
+11
-1
api-utils.ts
packages/next/next-server/server/api-utils.ts
+1
-1
user-error-async.js
test/integration/api-support/pages/api/user-error-async.js
+3
-0
index.test.js
test/integration/api-support/test/index.test.js
+7
-0
No files found.
packages/next/next-server/server/api-utils.ts
View file @
00179adc
...
@@ -54,7 +54,7 @@ export async function apiResolver(
...
@@ -54,7 +54,7 @@ export async function apiResolver(
apiRes
.
json
=
data
=>
sendJson
(
apiRes
,
data
)
apiRes
.
json
=
data
=>
sendJson
(
apiRes
,
data
)
const
resolver
=
interopDefault
(
resolverModule
)
const
resolver
=
interopDefault
(
resolverModule
)
resolver
(
req
,
res
)
await
resolver
(
req
,
res
)
}
catch
(
err
)
{
}
catch
(
err
)
{
if
(
err
instanceof
ApiError
)
{
if
(
err
instanceof
ApiError
)
{
sendError
(
apiRes
,
err
.
statusCode
,
err
.
message
)
sendError
(
apiRes
,
err
.
statusCode
,
err
.
message
)
...
...
test/integration/api-support/pages/api/user-error-async.js
0 → 100644
View file @
00179adc
export
default
async
(
req
,
res
)
=>
{
throw
new
Error
(
'User error'
)
}
test/integration/api-support/test/index.test.js
View file @
00179adc
...
@@ -63,6 +63,13 @@ function runTests(dev = false) {
...
@@ -63,6 +63,13 @@ function runTests(dev = false) {
expect
(
text
).
toBe
(
'Internal Server Error'
)
expect
(
text
).
toBe
(
'Internal Server Error'
)
})
})
it
(
'should throw Internal Server Error (async)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/api/user-error-async'
,
null
,
{})
const
text
=
await
res
.
text
()
expect
(
res
.
status
).
toBe
(
500
)
expect
(
text
).
toBe
(
'Internal Server Error'
)
})
it
(
'should parse JSON body'
,
async
()
=>
{
it
(
'should parse JSON body'
,
async
()
=>
{
const
data
=
await
fetchViaHTTP
(
appPort
,
'/api/parse'
,
null
,
{
const
data
=
await
fetchViaHTTP
(
appPort
,
'/api/parse'
,
null
,
{
method
:
'POST'
,
method
:
'POST'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment