Articles in this section
Category / Section

How to catch the failures from DataManager request

You can catch the DataManager request failures in client side by using the ‘beforeSend’ method of DataManager.

This is demonstrated in the below sample code in which the default failureHandler is interpolated inside the ‘beforeSend‘ method of DataManager. So, you can handle the request failures in client side to get the failure details.

TS

const dataObj = new DataManager({
  url: SERVICE_URI + "api/Orders",
  adaptor: new CustomWebUrlAdaptor()
});
 
const beforeSendFn = (dataObj as any).beforeSend;
 
(dataObj as any).beforeSend = function (request: any, settings: any) {
  const fail = settings.failureHandler;
  settings.failureHandler = function (data) {
    console.log("Entered in global DataManager failureHandler");
    console.log(this.httpRequest);
    fail.call(this, data);
  };
  beforeSendFn.call(this, request, settings);
};

 

You can also get the failures inside the catch statement of DataManager while query execution.

 

TS

dataObj.executeQuery(new Query()).catch(e => {
  console.log('Error handled after query execution');
  console.log(e.error);
});

 

Demo: https://stackblitz.com/edit/angular-data-manager-failure?file=app.component.ts

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied