Commit ddf1299
committed
WIP: incorrect no. of args for superagent callback
The plugin was failing to fetch the repos when
configuring a github account for the first time OR
when trying to do a "Refresh Account" from the web
page.
There were a couple of issues here:
a. JSON.parse was not necessary since superagent
returns a parsed object if we receive json.
https://visionmedia.github.io/superagent/#parsing-response%20bodies
b. We were passing a callback with three arguments
to superagent in .end(callback)
for example in -
get_oauth2(uri, {per_page: 30, page: page},
access_token, function (error, response, body) {
// ^ here, we should send
// only error and response
//In any case superagent puts the body inside response.body
//https://visionmedia.github.io/superagent/
This may be verified by looking at
superagent/lib/node/index.js
Around line 623 - (debugs added)
Request.prototype.callback = function(err, res){
debug('When calling the callback - err is ' + JSON.stringify(err, null, 4));
var fn = this._callback;
debug("And the number of arguments the callback expects is: " + fn.length );
this.clearTimeout();
if (this.called) return console.warn('double callback!');
this.called = true;
if (2 == fn.length) return fn(err, res);//<====== we want this to be true
if (err) return this.emit('error', err);
debug("Here, we are sending the first parameter to the callback as the response, " +
"but GOTCHA - our callback thinks the first param is an error and THROWS!");
fn(res);
};
c. Still need to understand the presence of this.group and group()
as present in the comments in the code.
The reason why it fails near
get_github_repos(): Error with admin team memberships: [object Object]
is because, the previous function in the "Step" has a call to
get_oauth2(url, {}, token, group()) - which basically sends the last parameter
as it is to superagent. And thus we have an object with data received from the
API, which we think is an err.1 parent 489484d commit ddf1299
2 files changed
Lines changed: 39 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
155 | 156 | | |
156 | 157 | | |
157 | 158 | | |
| |||
173 | 174 | | |
174 | 175 | | |
175 | 176 | | |
176 | | - | |
177 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
178 | 180 | | |
179 | | - | |
| 181 | + | |
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
| |||
242 | 244 | | |
243 | 245 | | |
244 | 246 | | |
245 | | - | |
| 247 | + | |
| 248 | + | |
246 | 249 | | |
247 | 250 | | |
248 | 251 | | |
249 | | - | |
| 252 | + | |
250 | 253 | | |
251 | 254 | | |
252 | 255 | | |
| |||
267 | 270 | | |
268 | 271 | | |
269 | 272 | | |
| 273 | + | |
270 | 274 | | |
271 | 275 | | |
272 | 276 | | |
273 | 277 | | |
274 | 278 | | |
| 279 | + | |
275 | 280 | | |
276 | 281 | | |
277 | 282 | | |
| |||
343 | 348 | | |
344 | 349 | | |
345 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
346 | 354 | | |
347 | 355 | | |
348 | 356 | | |
349 | 357 | | |
350 | 358 | | |
351 | 359 | | |
352 | | - | |
| 360 | + | |
353 | 361 | | |
354 | 362 | | |
355 | 363 | | |
| |||
372 | 380 | | |
373 | 381 | | |
374 | 382 | | |
375 | | - | |
| 383 | + | |
376 | 384 | | |
377 | 385 | | |
378 | 386 | | |
379 | 387 | | |
380 | 388 | | |
381 | 389 | | |
382 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
383 | 394 | | |
384 | 395 | | |
385 | 396 | | |
| |||
388 | 399 | | |
389 | 400 | | |
390 | 401 | | |
391 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
392 | 412 | | |
393 | 413 | | |
394 | 414 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
53 | | - | |
| 54 | + | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
120 | | - | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
124 | | - | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
145 | | - | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| |||
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
213 | | - | |
| 214 | + | |
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| |||
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
238 | | - | |
| 239 | + | |
239 | 240 | | |
240 | 241 | | |
241 | 242 | | |
| |||
0 commit comments