rendrjs / rendr

Render your Backbone.js apps on the client and the server, using Node.js.
MIT License
4.09k stars 313 forks source link

Handling model Error if one model fail to give data in controller #523

Open krishna1st opened 5 years ago

krishna1st commented 5 years ago

I want to handle error if any model api get failed. I couldn't figure out, how can i handle it Here is more controller

index: function(params, callback) {
var phoneNo = params['phoneNo']; var spec = { model: {model: 'Email', params: params}, email: {model: 'Email', params: params}, phone: {model: 'Phone', params: params}, user: {model: 'User', params: params} }; if(phoneNo){ spec['hexagon'] = {model: 'Hexagon', params: params1}; } this.app.fetch(spec, {'timeout' : 5000}, function(err, result) { callback(err, result); });

In case if my Hexagon model get failed then it directly through the error and server show error like below

Error: ERROR fetching model 'hexagon' with options '{"parse":true,"headers":{"auth-key":"098bc240588033041ea1e6e47e9b880","User-Agent":"Rendr RestAdapter; Node.js"},"timeout":5000,"data":{"phoneNo":"XXXX","emailId":"XXX","userId":"123XXX}}'. Response: {"body":"404: Not Found404: Not Found","status":404} at error (/Users/kkc/Downloads/scrapbroker/src/admin_dashboard/node_modules/rendr/shared/fetcher.js:188:15) at Object.options.error (/Users/kkc/Downloads/scrapbroker/src/admin_dashboard/node_modules/backbone/backbone.js:1914:24) at /Users/kkc/Downloads/scrapbroker/src/admin_dashboard/node_modules/rendr/shared/syncer.js:99:17 at RestAdapter. (/Users/kkc/Downloads/scrapbroker/src/admin_dashboard/node_modules/rendr/server/data_adapter/rest_adapter.js:97:5) at Request.self.callback (/Users/kkc/Downloads/scrapbroker/src/admin_dashboard/node_modules/request/request.js:185:22) at emitTwo (events.js:126:13) at Request.emit (events.js:214:7) at Request. (/Users/kkc/Downloads/scrapbroker/src/admin_dashboard/node_modules/request/request.js:1161:10) at emitOne (events.js:116:13) at Request.emit (events.js:211:7)

Is there any way where I can handle this error on controller or model side.

ghost commented 5 years ago

@krishna1st based on commit history it appears this repo is no longer maintained by Airbnb

alexindigo commented 5 years ago

@krishna1st Yes, Airbnb released it some time ago, so it's up for grabs. And all other involved parties moved on to React (or Vue) based frameworks like Next.js

If you're invested a lot into this project, feel free to create PR and we'll get it merged.