Better API traces.

This commit is contained in:
Julien Fontanet 2015-06-30 11:06:31 +02:00
parent 706871c12a
commit a51d6b9a74
2 changed files with 21 additions and 6 deletions

View File

@ -49,6 +49,7 @@
"js-yaml": "^3.2.7",
"json-rpc-peer": "^0.10.0",
"julien-f-unzip": "^0.2.1",
"kindof": "^2.0.0",
"lodash.assign": "^3.0.0",
"lodash.bind": "^3.0.0",
"lodash.difference": "^3.2.0",
@ -72,6 +73,7 @@
"lodash.sortby": "^3.1.4",
"lodash.startswith": "^3.0.1",
"make-error": "^1",
"ms": "^0.7.1",
"multikey-hash": "^1.0.1",
"proxy-http-request": "0.1.0",
"redis": "^0.12.1",

View File

@ -6,7 +6,9 @@ import Bluebird from 'bluebird'
import forEach from 'lodash.foreach'
import getKeys from 'lodash.keys'
import isFunction from 'lodash.isfunction'
import kindOf from 'kindof'
import map from 'lodash.map'
import ms from 'ms'
import schemaInspector from 'schema-inspector'
import {
@ -268,7 +270,7 @@ export default class Api {
}
async call (session, name, params) {
debug('%s(...)', name)
const startTime = Date.now()
const method = this.getMethod(name)
if (!method) {
@ -300,14 +302,25 @@ export default class Api {
result = true
}
debug('%s(...) → %s', name, typeof result)
debug(
'%s(...) [%s] ==> %s',
name,
ms(Date.now() - startTime),
kindOf(result)
)
return result
} catch (error) {
if (error instanceof JsonRpcError) {
debug('Error: %s(...) → %s', name, error)
} else {
console.error(error && error.stack || error)
debug(
'%s(...) [%s] ==> %s',
name,
ms(Date.now() - startTime),
error
)
const stack = error && error.stack
if (stack) {
console.error(stack)
}
throw error