XRM-OSS / Xrm-WebApi-Client

A promise-based JavaScript library for the Microsoft Dynamics CRM WebApi - TypeScript type definitions available
https://xrm-oss.github.io/Xrm-WebApi-Client/
MIT License
100 stars 28 forks source link

Problem catching sync errors #24

Closed jlaurila closed 6 years ago

jlaurila commented 6 years ago

Hi, I don't seem to be able to catch errors when using synchronous mode. The following code will cause SendSync to throw an error "Uncaught Error: Not Found: Resource not found for the segment ..." but this will not be caught by the catch clause. Tested in Chrome and Firefox.

var request = {
                entityName: "thisdoesntexists",
                async: false
            };

try {
WebApiClient.Retrieve(request);
} catch (err) {
console.log(err);
};

I'm not a JavaScript guru so sorry if this is a trivial question, but how to catch the error in this case? In async mode the error is caught as expected.

DigitalFlow commented 6 years ago

Hey @jlaurila,

I'll take a look at it and provide you a sample or bug fix if needed as fast as possible.

Kind Regards, Florian

DigitalFlow commented 6 years ago

Hey @jlaurila,

sorry for the delay. I just published v3.6.5, which should allow you to catch errors as you showed in your code snippet. Please give me some feedback, whether it is working for you now.

Kind Regards, Florian

jlaurila commented 6 years ago

Thank you for the fix. There seems to be some breaking change to sync batch requests. Previously I was able to process the response, but now this line is called and it seems to lose the return value: https://github.com/DigitalFlow/Xrm-WebApi-Client/blob/69a1604ca2aad29229fd12055d751958b02e4979/src/js/WebApiClient.Core.js#L518

Previously this line was inside onload event handler function but now it returns from the SendSync directly and the response object is not returned.

DigitalFlow commented 6 years ago

Sorry for the issue, tests were passing. This will get a regression test. In the meantime: Can you try deleting the else condition that you referenced and check, if it behaves correctly?

DigitalFlow commented 6 years ago

Hey @jlaurila,

I just released v3.6.6, which contains a bugfix and a regression test for your issue with synchronous batch requests. Please give me some feedback, if your issues are resolved.

Kind Regards, Florian

DigitalFlow commented 6 years ago

Hey @jlaurila,

I'll close this. Please reopen if you're still having issues.

Kind Regards, Florian