Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add support onError action/event in server side code #359

Closed
hype11 opened this issue Jun 17, 2019 · 5 comments
Closed

Please add support onError action/event in server side code #359

hype11 opened this issue Jun 17, 2019 · 5 comments

Comments

@hype11
Copy link

hype11 commented Jun 17, 2019

There is no action/event to handle errors in a custom way at server side.
There is a property "Log" (in Devart.Data.Linq.DataContext) for logging statements etc. but nothing which is fired in error case.

@AlekseyMartynov
Copy link
Contributor

You can catch and handle server errors using a try-catch block:

try {
    // Use DataSourceLoader
} catch(Exception x) {
    // handle the error
}

@hype11
Copy link
Author

hype11 commented Jun 25, 2019

I use it in this way:
DataSourceLoader.Load(IQueryable, DataSourceLoadOptions)
The IQueryable is executed out of controller scope, so I cannot add a simple try-catch, because the IQueryable is executed in DevExpress logic or while serializing.
I hope it's understandable.

@AlekseyMartynov
Copy link
Contributor

AlekseyMartynov commented Jun 25, 2019

Now I understand that you need to catch exceptions that occur during the delayed enumeration of the result.

Possible solutions:

1. Force JSON serialization

try {
    var loadResult = DataSourceLoader.Load(source, loadOptions);
    return Content(JsonConvert.SerializeObject(loadResult), "application/json");
} catch(Exception x) {
    // TODO
    throw;
}

2. Force enumeration (feature request #347)

try {
    var loadResult = DataSourceLoader.Load(source, loadOptions);
    if(loadResult.data is IQueryable)
        loadResult.data = loadResult.data.Cast<Object>().ToArray();
    return loadResult;
} catch(Exception x) {
    // TODO
    throw;
}

@hype11
Copy link
Author

hype11 commented Jun 27, 2019

Thank you for your help. I implemented the executing of the Queryable. In my case I could not execute the query in all cases, because the "IsCountQuery"-request throws an exception. So in future, it would be nice to have a possiblity to add a logger function.

@hype11 hype11 closed this as completed Jun 27, 2019
@AlekseyMartynov
Copy link
Contributor

Thank you. I updated the code snippets. Now they handle IsCountQuery errors, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants