-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathd_methods.js
More file actions
44 lines (43 loc) · 1.08 KB
/
d_methods.js
File metadata and controls
44 lines (43 loc) · 1.08 KB
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
const axios = require("axios");
class Requestor {
headers;
constructor(auth_token, version) {
this.headers = {
authorization: `Bearer: ${auth_token}`,
"X-Version": version,
};
}
async get_post_response(url, data) {
try {
const options = {
headers: this.headers,
};
const response = await axios.post(url, data, options);
if (response.status != 200) {
this.Reporter.log(`Request not valid for url ${url}`);
}
return response;
} catch (e) {
let error_data = {
type: "ErrorReport",
message: "Request failure",
error: e.string,
data: {
url: url,
data: data,
},
};
this.Reporter.request_report.push(error_data);
if (!e.isAxiosError) {
this.Reporter.log("PROBLEM");
}
const err = e;
if (err) {
this.Reporter.log(err.code);
this.Reporter.log(err.response && err.response.status);
this.Reporter.log(err.response && err.response.data);
}
throw "Error with request";
}
}
}