Commit a81c5d3c authored by Pavel Mashliakovskiy's avatar 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
......@@ -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
}
......@@ -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
}
......@@ -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))
}
......@@ -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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment