Last change
on this file since 469 was
468,
checked in by hendrikvanantwerpen, 12 years ago
|
Improved authentication
- Authentication cannot be cancelled, removing a lot of weird race
conditions.
- We offer a request provider that has automatic retry in case of
authentication failures.
- Reduced dependency on LoginDialog? by having it act independent
based on events. Other modules can just depend on 'session'.
|
File size:
700 bytes
|
Rev | Line | |
---|
[468] | 1 | var q = require('q'), |
---|
| 2 | request = require('request'), |
---|
[466] | 3 | url = require('url'), |
---|
| 4 | _ = require('underscore'); |
---|
| 5 | |
---|
[468] | 6 | module.exports = function(url, options) { |
---|
[466] | 7 | |
---|
[468] | 8 | var dfd = q.defer(); |
---|
| 9 | dfd.response = q.defer(); |
---|
| 10 | |
---|
[466] | 11 | options = options |
---|
| 12 | ? _.clone(options) |
---|
| 13 | : {}; |
---|
[468] | 14 | options.uri = url || options.uri; |
---|
[466] | 15 | |
---|
[468] | 16 | request(options,function(err,res,body){ |
---|
| 17 | if ( err ) { |
---|
| 18 | dfd.response.reject(err); |
---|
| 19 | } else { |
---|
| 20 | if ( res.statusCode >= 200 && res.statusCode < 300 ) { |
---|
| 21 | dfd.resolve(body); |
---|
| 22 | } else { |
---|
| 23 | dfd.reject(body); |
---|
| 24 | } |
---|
| 25 | } |
---|
| 26 | dfd.response.resolve(res); |
---|
[466] | 27 | }); |
---|
[468] | 28 | |
---|
| 29 | return dfd.promise; |
---|
| 30 | |
---|
[466] | 31 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.