cocos creator2.2捕獲異常。包括客戶端與瀏覽器端。客戶端異常上傳服務器
if(cc.sys.isNative) {
window.__errorHandler = function (errorMessage, file, line, message, error) {
let exception = {};
exception.errorMessage = errorMessage;
exception.file = file;
exception.line = line;
exception.message = message;
exception.error = error;
window.exception = JSON.stringify(exception);
console.log(window.exception );
//上傳服務器
var url = "http://192.168.6.6:1001/client/clientlog" //換成自己的url
var xhr = new XMLHttpRequest();
xhr.open("post",url);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(window.exception);
};
} else if(cc.sys.isBrowser) {
window.onerror = function (errorMessage, file, line, message, error) {
let exception = {};
exception.errorMessage = errorMessage;
exception.file = file;
exception.line = line;
exception.message = message;
exception.error = error;
window.exception = JSON.stringify(exception);
console.log(exception);
};
}