2muchcoffeecom / ngx-restangular

Restangular for Angular 2 and higher versions
https://2muchcoffee.com/ngxrestangular-app-development
MIT License
781 stars 110 forks source link

Hi , I am using ngx-restangular in my project. When one of my service returns true as a response. I am getting the below error: Cannot create property 'route' on boolean 'true' #96

Closed maheshnerella closed 7 years ago

maheshnerella commented 7 years ago

core.es5.js:1020 ERROR TypeError: Cannot create property 'route' on boolean 'true' at restangularizeBase (ngx-restangular.js:52) at restangularizeElem (ngx-restangular.js:182) at SafeSubscriber.okCallback [as _next] (ngx-restangular.js:358) at SafeSubscriber.__tryOrUnsub (Subscriber.js:238) at SafeSubscriber.next (Subscriber.js:185) at Subscriber._next (Subscriber.js:125) at Subscriber.next (Subscriber.js:89) at CatchSubscriber.Subscriber._next (Subscriber.js:125) at CatchSubscriber.Subscriber.next (Subscriber.js:89) at MapSubscriber._next (map.js:83) 

rshchpkn commented 7 years ago

Hello @maheshnerella, Can you please describe what do you mean by "When one of my service returns true as a response". Is it one of the endpoints? Also can you please provide more details about the issue.

paullauyc commented 7 years ago

I got the almost same problem too. the case is... when my service function get the base64 image string as a response. I am getting the below error. core.es5.js:1084 ERROR TypeError: Cannot create property 'route' on string 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJ8AAACfCAYAAADnGwvgAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPue....=' at restangularizeBase (ngx-restangular.js:52) at restangularizeElem (ngx-restangular.js:182)

My restangular code is getProfilePicture(id:string){ return this.restangular.one('web').one('img').one('base64',id).get().map(res => { return res.json(); }); }

But it is no problem when i am using the angular/http package. the code as below: getProfilePictureHttp(id:string){ return this.http.get(http://api.service.com/essapi/api/web/img/base64/${id}).map(res => { });

rshchpkn commented 7 years ago

Hello @maheshnerella @paullauyc, restagular expects object in response. Then it extends this object with own fields and methods. Server should return Json as response e.g:

{
  data: 'string or boolean'
}
paullauyc commented 7 years ago

Big Thanks.

gerardolima commented 6 years ago

It definitely doesn't make sense to create an artificial anonymous object to return a boolean value.

I think whenever an endpoint returns a boolean it should be handled as a service and not as a completely artificial object created just to hold a value. What's the use of the augmented methods to this object, anyway? Would it make any sense to call save() or remove() on objects like these?