-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
executable file
·38 lines (35 loc) · 889 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict'
const URI = require('urijs')
const moment = require("moment")
exports.buildOrchestration = (name, beforeTimestamp, method, url, requestContent, res, body) => {
let uri = new URI(url)
if (res == undefined || res == null || res == false) {
var statusCode = 500
var header = JSON.stringify({
"response_header": "Empty Header Returned"
})
var time = moment().format()
} else if ('statusCode' in res) {
var statusCode = res.statusCode
var header = res.headers
}
if(typeof body == 'object') {
body = JSON.stringify(body)
}
return {
name: name,
request: {
method: method,
body: requestContent,
timestamp: beforeTimestamp,
path: uri.path(),
querystring: uri.query()
},
response: {
status: statusCode,
headers: header,
body: body,
timestamp: new Date()
}
}
}