-
Notifications
You must be signed in to change notification settings - Fork 1
/
send-error.ts
69 lines (60 loc) · 1.68 KB
/
send-error.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { ElectronService } from 'ngx-electron';
import { Injectable } from '@angular/core';
@Injectable()
export class SendError {
constructor(private _electronService: ElectronService) {}
public exec(
version: string,
code: string,
category: string,
title: string,
detail: string
): void {
const saveData = {
OS: this._electronService.remote.require('os').platform(),
version: version,
code: code,
category: category,
title: title,
detail: detail
};
const data = {
saveData: JSON.stringify(saveData),
action: 'append',
sheetName: 's0',
actionParam: 0
}; // POSTメソッドで送信するデータ
const xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.onreadystatechange = function() {
const READYSTATE_COMPLETED = 4;
const HTTP_STATUS_OK = 200;
if (
this.readyState === READYSTATE_COMPLETED &&
this.status === HTTP_STATUS_OK
) {
console.log(this.responseText);
}
};
xmlHttpRequest.open(
'POST',
'https://script.google.com/macros/s/AKfycbxt8g9KxiD1hp_W1XQzw4tzmsIF1qVigRLF-v87ngWtqqU31JXu/exec'
);
xmlHttpRequest.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded'
);
xmlHttpRequest.send(this.encodeHTMLForm(data));
}
private encodeHTMLForm(data: any) {
const params = [];
for (const name in data) {
if (!name.hasOwnProperty(name)) {
continue;
}
const value = data[name];
const param = encodeURIComponent(name) + '=' + encodeURIComponent(value);
params.push(param);
}
return params.join('&').replace(/%20/g, '+');
}
}