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'
|
||||
|
||||
const DEBUG = process.env.NODE_DEBUG === 'hafas-client'
|
||||
|
||||
const {join} = require('path')
|
||||
const createHash = require('create-hash')
|
||||
let captureStackTrace = () => {}
|
||||
if (process.env.NODE_DEBUG === 'hafas-client') {
|
||||
captureStackTrace = require('capture-stack-trace')
|
||||
}
|
||||
const captureStackTrace = DEBUG ? require('capture-stack-trace') : () => {}
|
||||
const {stringify} = require('query-string')
|
||||
const Promise = require('pinkie-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?
|
||||
svcReqL: [data]
|
||||
})
|
||||
if (DEBUG) console.error(JSON.stringify(body))
|
||||
|
||||
const req = profile.transformReq({
|
||||
method: 'post',
|
||||
// todo: CORS? referrer policy?
|
||||
|
@ -84,6 +85,8 @@ const request = (profile, userAgent, opt, data) => {
|
|||
return res.json()
|
||||
})
|
||||
.then((b) => {
|
||||
if (DEBUG) console.error(JSON.stringify(b))
|
||||
|
||||
if (b.err) {
|
||||
err.message = b.err
|
||||
throw err
|
||||
|
|
Loading…
Add table
Reference in a new issue