-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.js
executable file
·47 lines (43 loc) · 1.22 KB
/
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
39
40
41
42
43
44
45
46
47
'use strict'
const URI = require('urijs')
const SENDEMAIL = require('./send_email')
const send_email = SENDEMAIL()
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()
send_email.send("Empty Response Data", "URL===> " + url + " Res===> " + res + " Body===> " + body + " Req===> " + requestContent + " Time===> " + time, () => {
})
} else if ('statusCode' in res || 'status' in res) {
if(res.statusCode) {
var statusCode = res.statusCode
} else if (res.status) {
var statusCode = res.status
}
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()
}
}
}