From 344b39a927fc8bf4d552a4cb7369800f83cf8ad2 Mon Sep 17 00:00:00 2001 From: jasonkneen Date: Fri, 21 Apr 2017 16:58:39 +0100 Subject: [PATCH] readme update, version bump --- package.json | 2 +- readme.md | 42 ++++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index dccab88..2b51702 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reste", - "version": "1.4.7", + "version": "1.4.8", "description": "A JavaScript REST / API helper for Titanium with Alloy Models/Collections support", "titaniumManifest": { "guid": "afafe8b0-b93b-771c-a9e5-4e71db81b9ff" diff --git a/readme.md b/readme.md index 6577c98..6788a55 100644 --- a/readme.md +++ b/readme.md @@ -210,37 +210,43 @@ You can pass the _optional_ **onError** and **onLoad** handlers, which will inte Note, in the **onError** handler, you can (as of 1.2.0) also handle any network errors better -- in the example above a **retry** method is returned so you can check the error, display a specific one, or handle any network issues, and if required, issue a **retry()** which will attempt the last call again. -If you've defined a **global onError()** within the configuration, it will passed onto any local `onError()` function defined for you methods. This way you can have something like: +By default, a local error handler will override the global error handler. So if you want to use both (so have local fire first and then pass off to global, then handle this within your own app). + +In this example we have a function in the same file as the RESTe config like this: + +```javascript +function globalError(e, retry) { + var dialog = Ti.UI.createAlertDialog({ + title: "Connection error", + message: "There was an error connecting to the server, check your network connection and retry.", + buttonNames: ['Retry'] + }); + + dialog.addEventListener("click", function() { + retry(); + }); + dialog.show(); +} +``` +and in our RESTe config we have: ```javascript methods: [{ name: "courses", post: "functions/getCourses", - onError: function(e, callback, globalOnError) { + onError: function(e, callback) { if (e.message) { alert(e.message); } else { - globalOnError(); - } - } + globalError(e, callback); + } }, { ... }], - onError: function(e, retry) { - var dialog = Ti.UI.createAlertDialog({ - title: "Connection error", - message: "There was an error connecting to the server, check your network connection and retry.", - buttonNames: ['Retry'] - }); - - dialog.addEventListener("click", function() { - retry(); - }); - dialog.show(); - }, + onError: globalError, ``` -If there is an error message within the response, you'll display it within an `alert()`, otherwise the normal global `onError()` handler will be used. +If there is an error message within the response, you'll display it within an alert(), otherwise the normal global onError() handler will be used. If you specify parameters required e.g. **videoId** then RESTe will automatically check for these in the parameters passed to the method, and raise an error if they're missing.