mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
debug hook logging request & response
This commit is contained in:
parent
e98cec1734
commit
3c104e2233
1 changed files with 7 additions and 4 deletions
|
@ -1,11 +1,10 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const DEBUG = process.env.NODE_DEBUG === 'hafas-client'
|
||||||
|
|
||||||
const {join} = require('path')
|
const {join} = require('path')
|
||||||
const createHash = require('create-hash')
|
const createHash = require('create-hash')
|
||||||
let captureStackTrace = () => {}
|
const captureStackTrace = DEBUG ? require('capture-stack-trace') : () => {}
|
||||||
if (process.env.NODE_DEBUG === 'hafas-client') {
|
|
||||||
captureStackTrace = require('capture-stack-trace')
|
|
||||||
}
|
|
||||||
const {stringify} = require('query-string')
|
const {stringify} = require('query-string')
|
||||||
const Promise = require('pinkie-promise')
|
const Promise = require('pinkie-promise')
|
||||||
const {fetch} = require('fetch-ponyfill')({Promise})
|
const {fetch} = require('fetch-ponyfill')({Promise})
|
||||||
|
@ -31,6 +30,8 @@ const request = (profile, userAgent, opt, data) => {
|
||||||
lang: opt.language || 'en', // todo: is it `eng` actually?
|
lang: opt.language || 'en', // todo: is it `eng` actually?
|
||||||
svcReqL: [data]
|
svcReqL: [data]
|
||||||
})
|
})
|
||||||
|
if (DEBUG) console.error(JSON.stringify(body))
|
||||||
|
|
||||||
const req = profile.transformReq({
|
const req = profile.transformReq({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
// todo: CORS? referrer policy?
|
// todo: CORS? referrer policy?
|
||||||
|
@ -84,6 +85,8 @@ const request = (profile, userAgent, opt, data) => {
|
||||||
return res.json()
|
return res.json()
|
||||||
})
|
})
|
||||||
.then((b) => {
|
.then((b) => {
|
||||||
|
if (DEBUG) console.error(JSON.stringify(b))
|
||||||
|
|
||||||
if (b.err) {
|
if (b.err) {
|
||||||
err.message = b.err
|
err.message = b.err
|
||||||
throw err
|
throw err
|
||||||
|
|
Loading…
Add table
Reference in a new issue