KendoUI datasource error event not raised on post with http 500 error - kendo-ui

I have a datasource with error handler defined as below. In the code I am intentionally causing an error on post and the server is returning 500 plus the json data, but the error event is not being raised on post. It does fire on the read event. See http://www.ageektech.com/simplyfundraising Open your browser debugger, refresh the page, click edit change any value, click update. Need help figuring out why the error event is not triggered.
Thanks,
Dan
schema : {
model : myModel,
data : "__ENTITIES",
errors: function(e) {
debugger;
// var xhr = e.xhr;
// var statusCode = e.status;
// var errorThrown = e.errorThrown;
//alert(JSON.parse(e.responseText).error.innererror.message);
return e.errors;
}

This is not the way to subscribe to the error event of the DataSource. The schema.errors setting is used for a different purpose.

Schema.errors should contain the name of the JSON field that contains error messages.
e.g.
schema: { errors: "Errors" }
For when you are returning JSON like:
{ "Errors": "Stuff went wrong" }

Related

How to properly handle Google SDK errors in Google App Script

I am writing a google web app which uses the Admin Directory a lot. However I was wondering how the error handling should be done since I do not get a proper error object back when a request to the api fails.
Example: I want to check if a custom schema exists and if not I want to do something else:
try{
var resp = AdminDirectory.Schemas.get("129898rgv", "someCustomSchema");
}catch(err){
// if schema does not exist do this
schemaNotExistFunction();
Logger.log(err);
}
Unfortunately I do not even get the http status code back from the err. Is there another way to handle errors in Google Apps Script?
Instead of
Logger.log(error)
use
Logger.log('%s, %s',error.message, error.stack);
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error for a complete list of Error instance properties
The above because Logger.log parses the parameter as string. When you pass an error object error.name is logged, by the other hand by using
Example
Running the following code in an standalone project using the new runtime (V8) will log a couple of messages.
function myFunction() {
try{
SpreadsheetApp.getUi();
} catch (error) {
Logger.log(error);
Logger.log('%s, %s', error.message, error.stack);
}
}
Another alternative is to use console.log instead of Logger.log
function myFunction() {
try{
SpreadsheetApp.getUi();
} catch (error) {
console.log(error);
console.log('%s, %s', error.message, error.stack);
}
}

Exception handling in Spring to align with Front-End

Gone through the link https://www.mkyong.com/spring-boot/spring-boot-ajax-example/
and observed the following
Don't type any name and hit search button - Bad Request - It Comes to Error Function of Ajax - User Can't be Empty - Form Validation. Ajax response is error in this case.
Type "Raju" in name field and hit search button - Business Error - Returned with Success Function. Ajax response is success in this case.
Assume i have thrown a run time exception in getSearchResultViaAjax() as below
AjaxResponseBody result = new AjaxResponseBody();
if(1==1) {
throw new RuntimeException();
}
The same Ajax error block is getting called.
error: function (e) {
var json = "<h4>Ajax Response Error </h4><pre>"
+ e.responseText + "</pre>";
$('#feedback').html(json);
console.log("ERROR pp : ", e);
$("#btn-search").prop("disabled", false);
}
So for Bad Request and Any Exception which comes Out side the box comes in error block
Which would be the right approach in the following ? If both of them is incorrect, help me with the best practice
Approach One
Throw form validation errors as as Ajax Response is ERROR with failure message to display
Throw Business validation errors as Ajax Response is SUCCESS with failure message to display
Throw any other exception as Ajax Response is ERROR with failure message to display
OR
Approach Two
Throw form validation error as Ajax Response is ERROR with failure message to display ('User Field is Empty')
Throw Business validation errors as Ajax Response is FAILURE with failure message to display ('User Name doesn't exist')
Throw any other exception as Ajax Response is ERROR with failure message to display
What would be the best approach or best practice ?

Error Message in Parse.com CloudCode - parse update?

My Cloud Code below was working fine until recently. Now I'm getting an error message (see below) but don't know why. My guess is Parse updated some of their API, but I do not know for sure. Also, I'm not a JavaScript person and therefore are hoping for some insight. Does somebody have a hint for me?
Parse.Cloud.define("setUserAnswersForQuestionIds", function(request, response) {
//the following line creates the error
var userId = request.user.get("userId"),
endpointURL = constants.apiURL2 + userId + "/preferences";
...
Here is the error message
{
"code": 141,
"error": "TypeError: Cannot call method 'get' of null\n at vivanda_api.js:241:29"
}
You're sending the request from a non-active user session: i.e. no one is logged in, thus request.user is null.

What kind of object does a Parse.Query.get()

Using the JavaScript SDK, what kind of object would be returned on the following query:
var groupQuery = new Parse.Query('some_valid_class');
var group = groupQuery.get('some_valid_object_id');
console.log(group);
I only see [object Object] in the log.
thanks!
On Cloud Code - You can't print objects directly as we usually does in console of browser.
You have to use console.log(JSON.stringify(yourObject))
Although the documentation doesn't say so, I believe the get method returns a Promise. Here is an example for getting the actual object taken from the documentation:
var query = new Parse.Query(MyClass);
query.get(myId, {
success: function(object) {
// object is an instance of Parse.Object.
},
error: function(object, error) {
// error is an instance of Parse.Error.
}
});
In the success-function a Parse.Object is provided.
You can find all the info at the Parse JavaScript SDK & Cloud Code Reference
Specific Parse.Query.get() documentation here: https://parse.com/docs/js/symbols/Parse.Query.html#get

Kendo UI - how to implement Error Handling on WEB API, non MVC using Kendo Grid

My Scenario is I created a Web API that returns an Active Directory Object.
I have this WEB API function create Active Directory User and creates a user that returns Active Directory Object that contains First Name , Last Name, Email, UserName, Etc... What If it got an error how would I handle this?
I'm using Kendo Grid InLine Edit http://demos.kendoui.com/web/grid/editing-inline.html
I want to show the error message as a pop up window
How would I do that???
Options
try catch the error and put in the Active Directory Object as
Exception???
How can I capture this is Kendo UI?
Throw the response and get the error message and show it in the Kendo Grid
//HttpResponseMessage msg = new HttpResponseMessage(HttpStatusCode.OK)
//{
// Content = new StringContent(string.Format("No User with ID = {0}.{1}", businessObject.UserName, ex.InnerException.ToString() )),
// ReasonPhrase = "CustomerID Not Found in Database!"
//};
//throw new HttpResponseException(msg);
OR
//var message = string.Format("Error Message: {0}", taskCreateADUser.ADExceptionDescription);
//throw new HttpResponseException(
// Request.CreateErrorResponse(HttpStatusCode.OK, message));
Thanks,
MarcLevin
Whenever KendoUI binds via Ajax it relies on serialized version of ModelState sent in json response. Essentially if ModelState is not valid, the json response returned to the widget (grid in this case) will contain something like this:
{
"Errors":{
"PropA":{
"errors":[
"Error1",
"Error2"
]
},
"PropB":{
"errors":[
"FUBAR"
]
}
}
}
Essentially your WebAPI will need to return similar data structure if you want the grid to respond to it.
This is regarding your Option 2. You would need to apply the following correctly to your specific scenario. This is just a sample of a really simple parse of the response and displaying an alert if an error is detected. This sample expects a JSON object containing an array of Items. You could definitely apply more advanced handling once you have the basic idea down.
$("#grid").kendoGrid({
dataSource: {
schema: {
data: function(data) {
if (data.Items[0].substring(0,37) == "allmyerrormessagesstartwiththisphrase"){
alert(data.Items[0];
} else {
return data.Items;
}
}
},
transport: {
read: "http://myurl.com/something/"
}
}
}
);

Resources