If you want to refuse the success callback, you need to do it explicitly, or reject a rejected promise, for example. return Promise.reject('error occurred'); or by throwing.
In addition, you should not use the Promise constructor in your case, since fetch already returns a promise object:
function a(url, config) { if (!config) config = {}; config = Object.assign(config, { headers: { 'content-type': 'application/json;charset=utf-8' } }); return fetch(url, config).then( function(res) { if (res.status == 200 && res.ok) { console.log("Promise resolved") return res.json(); } console.log("Promise rejected"); throw 'promise rejected'; }, function(rej) { console.log("promise rejected"); throw 'promise rejected'; } ); }
source share