Skip to content

Commit

Permalink
feat(Server): add error details
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Nov 30, 2018
1 parent f69668b commit 545867a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/comms/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default abstract class Server {
// to include in the response JSON
response.result = (result instanceof Thing) ? this.processor.exportObject(result) : result
} catch (exc) {
response.error = (exc instanceof JsonRpcError) ? exc : new JsonRpcError(-32603, `Internal error: ${exc.message}`)
response.error = (exc instanceof JsonRpcError) ? exc : new JsonRpcError(-32603, `Internal error: ${exc.message}`, { trace: exc.stack })
}

if (this.logging !== undefined) {
Expand Down
7 changes: 5 additions & 2 deletions tests/comms/Server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import Server from '../../src/comms/Server'
// @ts-ignore Ignore that this is an abstract class
const server = new Server()

function check(request: null | object, response: object){
expect(JSON.parse(server.recieve(JSON.stringify(request)))).toEqual(response)
function check(request: null | object, expected: object){
const response = JSON.parse(server.recieve(JSON.stringify(request)))
// Remove any error response details e.g. traceback
if (response.error && response.error.data) delete response.error.data
expect(response).toEqual(expected)
}

test('handle', () => {
Expand Down

0 comments on commit 545867a

Please sign in to comment.