How can we improve Breeze.js?

breeze.js createError function can't handle datajs errors

My ODataController Post method was updating its entity's CreatedOn property with DateTime.Now value before it's saving to database.

Apparently datajs doesn't like DateTime.Now value and gives an error with "Invalid date/time value".

File: datajs-1.1.2.js - Line 2133

After datajs throws the exception, it falls to breeze.js createError function. However, since it's expecting error.response property, it fails to continue by giving "response is undefined" message.

File: breeze.debug.js - Line: 15302

I've updated the function by adding a check for response property;

function createError(error, url) {
// OData errors can have the message buried very deeply - and nonobviously
// this code is tricky so be careful changing the response.body parsing.
var result = new Error();

var response = error.response;
var hasResponse = typeof response !== "undefined";
result.message = hasResponse ? response.statusText : error.message;
result.statusText = hasResponse ? response.statusText : error.message;
result.status = hasResponse ? response.statusCode : -1;

// non std
if (url) result.url = url;
result.body = hasResponse ? response.body : error.message;

if (hasResponse) {
if (response.body) {
var nextErr;
try {
var body = JSON.parse(response.body);
result.body = body;
// OData v3 logic
if (body['odata.error']) {
body = body['odata.error'];
}
var msg = "";
do {
nextErr = body.error || body.innererror;
if (!nextErr) msg = msg + getMessage(body);
nextErr = nextErr || body.internalexception;
body = nextErr || body;
} while (nextErr);
if (msg.length > 0) {
result.message = msg;
}
} catch (e) {

}
}
}

return result;
}

You may want to check this issue.

11 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Serkan Holat shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • John Sudds commented  ·   ·  Flag as inappropriate

    I've also had to update the createError function both to handle ad-hoc exceptions thrown from datajs, and correctly report timeout errors.

Feedback and Knowledge Base