Wednesday, 15 July 2015

breeze - Query failed and the error.message is the data -



breeze - Query failed and the error.message is the data -

a friend's query failing. fortunately, catching in fail callback (you have fail callback every server call, right?). here's kind of had:

var getpersons = function(personsobservable) { homecoming entityquery.from('person') .using(manager).execute() .then(querysucceeded).fail(queryfailed); } function queryfailed(error) { var msg = 'error retreiving data. ' + error.message; logerror(msg, error); throw error; }

the error.message showed json info ... looked bit this:

"[{"$id":"1","$type":"person, projectname","id":12,"firstname":"bob","lastname":"smith","email":"bs@contoso.com","blog":"http://bs.contoso.com","twitter": ..."

wat? examined error.xhr provides total ajax xhr object used query. see http status code 200 ... meaning cool server. fact had real info pretty much said same thing.

so why breeze failing? how diagnose problem?

breeze might failing. there's chance problem lies elsewhere. if breeze fails, there meaningful error message. error message not meaningful. provide clues.

check success callback first

the fail callback can invoked (1) if operation fails or (2) if success callback fails. if operation fails, you've got breeze-related problem. if success callback fails, have application code problem.

to determine which, set breakpoint on first line of success callback (in case, first line of querysucceeded). if nail breakpoint, know breeze has done bit , has handed off you. step through callback find mistakes yours and, therefore, easy fix.

check custom entitytype constructors , initializers

in case did not success callback. went wrong breeze tried create cached entities out of json info server. be?

there many potential causes. breeze bug. best, though, eliminate airplane pilot error first. did write custom constructor or initializer entitytype?

he did. had initializer added fullname calculated property person. looked sort of this:

metadatastore.registerentitytypector('person', null, personinitializer); function personinitializer(person) { person.fullname = ko.computed(function () { homecoming entity.firstname() + ' ' + person.lastname(); }); }

he didn't see problem. next diagnostic procedure, put breakpoint on initializer.

sure plenty ... had typo ...

// "entity" not exist. null object error homecoming entity.firstname() + ' ' + person.lastname();

as changed entity person, well.

i can't explain @ moment why null object reference manifested q promise fail error json person info in message. unusual stuff happens in javascript. clues there:

server delivered data failed before getting success callback data person have person initializer (or constructor)

read clues , you'll know look.

hope tip saves grayness hair , bald head.

breeze

No comments:

Post a Comment