Get Free Trial

Custom DataSource API Error message from server.

Re-Open
Parmod asked on March 16, 2021

Hi Flexmonster,

How can I add custom error message handle for Datasource API?

Attachments:
Capture.PNG

6 answers

Public
Vera Didenko Vera Didenko Flexmonster March 16, 2021

Hello,
 
Thank you for writing to us. 
 
Flexmonster provides the olapstructureerror and the queryerror events that can be used to detect when an error occurs. 
Using these events, you could provide your custom error handling logic.
 
Also, it is possible to customize the error messages via localization
Here is a link to the error messages defined for the custom data source API in the localization file.
We would like to mention that localization can be specified fully via file or partially by specifying specific labels (see example). 
 
Please let us know if this helps.
 
Kind regards, 
Vera

Public
Parmod May 5, 2021

Hi Vera,

We tried everything but we are not able to get the error message response, which we are sending from the server i.e

response : {errorMinorCode: 8000, errorMajorCode: 101, message: "Custom Error message", GUID: 100876435}

And in queryerror , we don’t get the response message which we are sending from the server.

flexmonster.on('queryerror', function () {
  alert('Query error!');
});

Regards,
Parmod

Public
Vera Didenko Vera Didenko Flexmonster May 6, 2021

Hello, Parmod,
 
Thank you for reaching out to us and for providing additional details.
 
Regarding the queryerror event, please note that the error message is not passed in the event handler. This event helps to detect if some error occurred while running the query so that some custom error handling logic could be executed.
 
To provide custom error messages from your server, please specify the error status code (for example, 400, 404, 500, etc.) along with the server’s response and pass the custom message in the response. This way, Flexmonster will display your custom errors instead of the default ones.
 
Here is an example of how custom error messages are provided in a Node.js implementation of the custom data source API

cube.post("/select", async (req, res) => {

try {

const result = await getSelectResult(req.body.index, req.body.query, req.body.page);
res.json(result);

} catch (err) {

handleError(err, res);

}

});


function handleError(err, res, status) {

...

if (err instanceof URIError) {
status = 400;
}

status = status || 500;

var message = "Unknown server error.";

if (typeof err == "string") {
message = err;
} else if (err.message) {
message = err.message;
}

res.status(status).json({message});
}

 
Also, we have prepared a simple JSFiddle example for illustration: https://jsfiddle.net/flexmonster/aujgwso8/.
In the example, to simulate a custom error scenario, we specified a callback function instead of an URL in the "url" dataSource object’s property.
The function accepts three parameters: the request, on success callback function, and on error callback function. Through the error callback function a custom error message is passed to Flexmonster: {"message": "Custom error message"}.
 
Please let us know if this helps. 
Looking forward to your response.
 
Kind regards,
Vera

Public
Parmod May 6, 2021

Hi Vera,

Thanks for the response but it will not solve our problem.

We have a Standard Error response pattern from the server with status code as 400. The error response cannot be changes because of the security policies and it contain various information regarding actual error.

response : {errorMinorCode: 8000, errorMajorCode: 101, message: "Custom Error message", GUID: 100876435}

Therefore we need the error object which we are sending from the server to display the error message with actual error reference number.

Regards,
Parmod

Public
Vera Didenko Vera Didenko Flexmonster May 7, 2021

Hello, Parmod,
 
Thank you for your reply. 
 
A possible workaround is to use the callback function approach to connect Flexmonster to your custom data source API endpoint. 
This way, it is possible to override the default error pop-up by running the alert() API call when your server responds with an error.
 
We have prepared a simple JSFiddle for illustration purposes: https://jsfiddle.net/flexmonster/vrfhb68o/.
In the example, we connected Flexmonster to our sample custom data source API endpoint through the callback function approach.
If an error occurs (see line 59), Flexmonster is notified about the error through the error callback handler. The custom error is displayed with the alert() API call. Here is a modified version of the example to illustrate the custom error behavior: https://jsfiddle.net/flexmonster/ht20ogkp/. In this case, the error is simulated by requesting a nonexistent index.
 
Please let us know if this works.
 
Kind regards,
Vera

Public
Parmod May 11, 2021

Hi Vera,
Thanks, It worked.

Regards,
Parmod

Please login or Register to Submit Answer