Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
unitybase
ubjs
Commits
a81c5d3c
Commit
a81c5d3c
authored
Aug 01, 2021
by
Pavel Mashliakovskiy
🤹🏻
Browse files
autotest for Exception throws by native and catch in JS must not force HTTP response to 500
parent
127b1703
Pipeline
#31032
skipped with stage
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
apps/autotest/models/TST/_autotest/0160_testJSMixin.js
View file @
a81c5d3c
...
...
@@ -33,4 +33,4 @@ module.exports = function runJSMixinsTests (options) {
})
defValues
=
tstIDMapAddNew
.
resultData
.
data
[
0
]
assert
.
strictEqual
(
defValues
[
1
],
'
val-tst_idmap
'
,
`testMixin should sets 'val-tst_idmap' as code default for tst_IDMapping but got
${
defValues
[
1
]}
`
)
}
\ No newline at end of file
}
apps/autotest/models/TST/_autotest/0170_testServerSideReporting.js
View file @
a81c5d3c
...
...
@@ -3,7 +3,6 @@
* Date: 2021-03-15
* Test server-side reporting
*/
const
assert
=
require
(
'
assert
'
)
const
cmdLineOpt
=
require
(
'
@unitybase/base
'
).
options
const
argv
=
require
(
'
@unitybase/base
'
).
argv
...
...
@@ -22,7 +21,7 @@ module.exports = function runJSMixinsTests (options) {
conn
.
xhr
({
endpoint
:
'
rest/tst_service/testServerRendering
'
,
data
:
{
reportCode
:
"
test
"
,
responseType
:
"
html
"
,
reportParams
:
{}
reportCode
:
'
test
'
,
responseType
:
'
html
'
,
reportParams
:
{}
}
})
}
\ No newline at end of file
}
apps/autotest/models/TST/_autotest/test_req_resp.js
View file @
a81c5d3c
...
...
@@ -24,6 +24,7 @@ module.exports = function runHTTPTest (options) {
testHTTP
(
conn
,
domain
,
session
)
testRest
(
conn
)
testUnicode
(
conn
)
testHandledException
(
conn
)
}
finally
{
session
.
logout
()
}
...
...
@@ -111,3 +112,15 @@ function testUnicode (conn) {
}
assert
.
throws
(
usualExc
,
/HTTP Error 500 - Internal Server Error/
,
'
Should hide JS errors in production mode
'
)
}
/**
* Exception throws by native and catch in JS must not force HTTP response to 500
* @param {SyncConnection} conn
*/
function
testHandledException
(
conn
)
{
let
resp
assert
.
doesNotThrow
(()
=>
{
resp
=
conn
.
post
(
'
/verifyThrowCatch
'
)
},
'
Exception throws by native and catch in JS must not force HTTP response to 500
'
)
assert
.
strictEqual
(
resp
.
catched
,
true
,
'
Expect { catched: true } but got
'
+
JSON
.
stringify
(
resp
))
}
apps/autotest/models/TST/appLevelMethod.js
View file @
a81c5d3c
...
...
@@ -363,3 +363,24 @@ function bodyParse (req, resp) {
resp
.
writeEnd
(
j
)
}
App
.
registerEndpoint
(
'
bodyParse
'
,
bodyParse
,
false
)
/**
* Verify throw / catch return user defined statusCode
* @param {THTTPRequest} req
* @param {THTTPResponse} resp
*/
function
verifyThrowCatch
(
req
,
resp
)
{
let
catched
=
false
try
{
UB
.
DataStore
(
'
tst_service
'
).
run
(
'
handledExceptionTest
'
,
{
execParams
:
{}
})
}
catch
(
e
)
{
catched
=
true
console
.
error
(
e
.
message
)
}
resp
.
statusCode
=
201
resp
.
writeHead
(
'
Content-Type: application/json; charset=UTF-8
'
)
resp
.
writeEnd
({
catched
})
}
App
.
registerEndpoint
(
'
verifyThrowCatch
'
,
verifyThrowCatch
,
true
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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