mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-26 16:26:44 +03:00
Cleanup AbstractFetch
and added fetchJSON mockup code for error handling regarding issue #49
This commit is contained in:
parent
4723e1241e
commit
fa7ea413dc
2 changed files with 176 additions and 172 deletions
35
dev/bootstrap.js
vendored
35
dev/bootstrap.js
vendored
|
|
@ -90,15 +90,13 @@ export default (App) => {
|
|||
cache: 'no-cache',
|
||||
redirect: 'error',
|
||||
referrerPolicy: 'no-referrer',
|
||||
credentials: 'same-origin'
|
||||
credentials: 'same-origin',
|
||||
headers: {}
|
||||
}, init);
|
||||
|
||||
init.headers.Accept = 'application/json';
|
||||
if (postData) {
|
||||
init.method = 'POST';
|
||||
init.headers = {
|
||||
// 'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||
};
|
||||
init.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
||||
postData.XToken = rl.settings.app('token');
|
||||
// init.body = JSON.stringify(postData);
|
||||
const formData = new FormData(),
|
||||
|
|
@ -115,7 +113,30 @@ export default (App) => {
|
|||
init.body = new URLSearchParams(formData);
|
||||
}
|
||||
|
||||
return fetch(resource, init).then(response => response.json());
|
||||
return fetch(resource, init).then(response => {
|
||||
if (!response.ok) {
|
||||
// return Promise.reject('Network response error: ' + response.status);
|
||||
throw new Error('Network response error: ' + response.status);
|
||||
}
|
||||
/* TODO: use this for non-developers?
|
||||
response.clone()
|
||||
let data = response.text();
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
// console.log(data);
|
||||
return Promise.reject(Notification.JsonParse);
|
||||
return {
|
||||
Result: false,
|
||||
ErrorCode: 952, // Notification.JsonParse
|
||||
ErrorMessage: e.message,
|
||||
ErrorMessageAdditional: data
|
||||
}
|
||||
}
|
||||
*/
|
||||
return response.json();
|
||||
});
|
||||
};
|
||||
|
||||
window.__APP_BOOT = fErrorCallback => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue