I have a react app that the user will enter info into a redux form and the function is called. I have a axios post that will not catch an error. I'm not sure what this is happening.
export function vehicleformsubmit(props){
const input={
rfidtag: rfidtag.value,
vin: vin.value,
vehzone: vehzone.value
};
var request=axios.post(`http://localhost:9000/api/bmwvehicle/create`, input);
return function(dispatch){
request.then((response) =>{
dispatch(createVehicleSuccess(response.data, response.status));
}).catch((error) =>{
if(error.response){
dispatch(vehicleHaveError(true));
}
});
};
}
This is that I get back:
createError.js:16 Uncaught (in promise) Error: Request failed with
status code 500
at createError (createError.js:16)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:77)
Related
I've this error when I click on my button:
Uncaught (in promise) Error: An object could not be cloned.
I start with electron, and I would like to take advantage of this topic to know the difference between invoke and send (I tried both, with the same error)
Main.js
ipcMain.handle('savePdf', (event, pdfFile) => {
console.log(event);
console.log(pdfFile);
return pdfFile;
}
preload.js
contextBridge.exposeInMainWorld('pdf', {
savePdf: (file) => ipcRenderer.invoke('savePdf', file),
})
rendered.js
const pdfFileInput = document.getElementById('input-file'); // OK
const pdfFile = pdfFileInput.files[0]; // OK
console.log(pdfFile); // OK
await pdf.savePdf(pdfFile);
I am trying to write a jest test for the xml2js parse.parseString, but when I pass in an invalid xml it just bypasses the parse.parseString function rather than return the error in the callback function. I want to trigger the error in the callback function.
import xml2js from 'xml2js';
const parser = new xml2js.Parser({
async: false
});
parser.parseString(`<_>&%xstest</_>`, (err, result) => {
if (err) {
console.log('error',err)
throw new Error(`Parser error: ${err}`);
}
console.log('result', result)
});
any idea on why I can not trigger the err in the callback of parse.parseString to call? I am unable to get parse.parseString to throw an error.
using Msal v1.0.2, loginPopup is not working from iFrame.
trying to get the UserAgentApplication instance using client_id. its throwing an exception:
TypeError: this.isCallback is not a function
at Object.UserAgentApplication (UserAgentApplication.ts:228)
const myMSALObj = Msal.UserAgentApplication(msalConfig);
myMSALObj.loginPopup(["user.read"]).then(function (loginResponse) {
return myMSALObj.acquireTokenSilent(accessTokenRequest);
}).then(function (accessTokenResponse) {
const token = accessTokenResponse.accessToken;
}).catch(function (error) {
//handle error
});
sample from . 'Quickstart for MSAL JS' works fine but when I try to integrate Msal inside iFrame of my JavaScript plugin code, its not working.
working code from sample:
var myMSALObj = new Msal.UserAgentApplication(msalConfig);
myMSALObj.handleRedirectCallback(authRedirectCallBack);
myMSALObj.loginPopup(requestObj).then(function (loginResponse) {
acquireTokenPopupAndCallMSGraph();
}).catch(function (error) {
//Please check the console for errors
console.log(error);
});
there was a typo causing this exception: TypeError: this.isCallback is not a function at Object.UserAgentApplication (UserAgentApplication.ts:228)
fix: const myMSALObj = new Msal.UserAgentApplication(msalConfig);
That should solve this exception issue.
I can not catch the error response with axios. How to do that?
I use something like:
axios
.post(...)
.then(response => {
console.log('Success: ', response)
}).catch(error => {
console.log('Error: ', error)
})
I see that the result of ajax request has 400 status code and the response body looks like {someField:["This field may not be blank"]} (Django backend). That's ok, I'm ready to process these errors in the catch handler.
But they go to the success handler instead. Why so? I see the following output in the console:
Success: Error: Request failed with status code 400
at createError (createError.js:16)
at settle (settle.js:18)
at XMLHttpRequest.handleLoad (xhr.js:77)
The success handler receives axios error object as the result. Why that may be and what to do next? This error object does not contain any usefull information.
UPD. Actually, the error object does contain the useful information, it contains the response object inside. So we can use:
axios
.post(...)
.then(response => {
if (response && response.response) {
console.log('This is also an error', response.response.status)
} else {
console.log('Success: ', response)
}
}).catch(error => {
console.log('Error: ', error)
})
But that looks super ugly.
The axios version is axios#0.16.2.
That's the big project, but I can not find any axios customizations.
Use Axios interceptors for the response. Check which status you want to force to fail as error so they go through the catch path whenever you receive said status code.
axios.interceptors.response.use(function (response) {
if (response.status === 400) {
return Promise.reject(response);
}
return response;
}, function (error) {
// Do something with response error
return Promise.reject(error);
});
If you are not receiving the expected status code, you might change the way you check the response in the interceptor. You can check any of the elements that Axios response is structured.
axios.interceptors.response.use(function (response) {
if (response.statusText !== 'OK') {
return Promise.reject(response);
}
return response;
}, function (error) {
// Do something with response error
return Promise.reject(error);
});
// Edit: Hm...this is an firebug bug in firefox. On chrome it works...
I'm using Laravel 5.3 with Vue 2.0 and the axios ajax library.
Here is a test controller, where i return a response from laravel:
public function testMethod() {
return response('this is an error', 500);
}
Here is my ajax call:
http(`fetch-data`).then(response => {
const data = response.data;
console.log(data);
}).catch(error => {
console.log(error); // <- This doens't work, he show my nothing
alert(error);
});
The problem is, i need the error message which is returned from laravel into my client catch. But if i console.log them, he show me nothing. If i alert the error, he gives me the following message: Error: Request failed with status code 500.
Why can't i access something like error.statusCode, error.statusMessage?
Try
return response()->json('this is an error', 500);