Skip to content

Commit 3e3a0b2

Browse files
Throwing caught exceptions during JWT token refresh (#77)
* Bug fix (#71) - When refreshing JWT token, throw caught exceptions. * Adding generated files * Fixing payload types
1 parent fa2b1e4 commit 3e3a0b2

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

lib/client.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,38 +54,40 @@ var DgraphClient = (function () {
5454
}
5555
DgraphClient.prototype.alter = function (op, metadata, options) {
5656
return __awaiter(this, void 0, void 0, function () {
57-
var c, payload, operation, e_1, pl;
57+
var c, payload, operation, _a, _b, e_1, _c, _d;
5858
var _this = this;
59-
return __generator(this, function (_a) {
60-
switch (_a.label) {
59+
return __generator(this, function (_e) {
60+
switch (_e.label) {
6161
case 0:
6262
this.debug("Alter request:\n" + util_1.stringifyMessage(op));
6363
c = this.anyClient();
6464
operation = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
6565
return [2, c.alter(op, metadata, options)];
6666
}); }); };
67-
_a.label = 1;
67+
_e.label = 1;
6868
case 1:
69-
_a.trys.push([1, 3, , 7]);
69+
_e.trys.push([1, 3, , 8]);
70+
_b = (_a = types).createPayload;
7071
return [4, operation()];
7172
case 2:
72-
payload = _a.sent();
73-
return [3, 7];
73+
payload = _b.apply(_a, [_e.sent()]);
74+
return [3, 8];
7475
case 3:
75-
e_1 = _a.sent();
76+
e_1 = _e.sent();
7677
if (!(isJwtExpired(e_1) === true)) return [3, 6];
7778
return [4, c.retryLogin(metadata, options)];
7879
case 4:
79-
_a.sent();
80+
_e.sent();
81+
_d = (_c = types).createPayload;
8082
return [4, operation()];
8183
case 5:
82-
payload = _a.sent();
83-
_a.label = 6;
84-
case 6: return [3, 7];
85-
case 7:
86-
pl = types.createPayload(payload);
87-
this.debug("Alter response:\n" + util_1.stringifyMessage(pl));
88-
return [2, pl];
84+
payload = _d.apply(_c, [_e.sent()]);
85+
return [3, 7];
86+
case 6: throw e_1;
87+
case 7: return [3, 8];
88+
case 8:
89+
this.debug("Alter response:\n" + util_1.stringifyMessage(payload));
90+
return [2, payload];
8991
}
9092
});
9193
});

lib/txn.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ var Txn = (function () {
238238
}); }); };
239239
_a.label = 1;
240240
case 1:
241-
_a.trys.push([1, 3, , 7]);
241+
_a.trys.push([1, 3, , 8]);
242242
return [4, operation()];
243243
case 2:
244244
_a.sent();
245-
return [3, 7];
245+
return [3, 8];
246246
case 3:
247247
e_4 = _a.sent();
248248
if (!(client_1.isJwtExpired(e_4) === true)) return [3, 6];
@@ -252,9 +252,10 @@ var Txn = (function () {
252252
return [4, operation()];
253253
case 5:
254254
_a.sent();
255-
_a.label = 6;
256-
case 6: return [3, 7];
257-
case 7: return [2];
255+
return [3, 7];
256+
case 6: throw util_1.isAbortedError(e_4) ? errors_1.ERR_ABORTED : e_4;
257+
case 7: return [3, 8];
258+
case 8: return [2];
258259
}
259260
});
260261
});

src/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ export class DgraphClient {
5151
if (isJwtExpired(e) === true) {
5252
await c.retryLogin(metadata, options);
5353
payload = await operation();
54+
} else {
55+
throw e;
5456
}
5557
}
56-
const pl = types.createPayload(payload);
58+
const pl: types.Payload = types.createPayload(payload);
5759
this.debug(`Alter response:\n${stringifyMessage(pl)}`);
5860

5961
return pl;

src/txn.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,15 @@ export class Txn {
227227

228228
this.ctx.setAborted(true);
229229
const c = this.dc.anyClient();
230-
const operation = async() => c.commitOrAbort(this.ctx, metadata, options);
230+
const operation = async () => c.commitOrAbort(this.ctx, metadata, options);
231231
try {
232232
await operation();
233233
} catch (e) {
234234
if (isJwtExpired(e) === true) {
235235
await c.retryLogin(metadata, options);
236236
await operation();
237+
} else {
238+
throw isAbortedError(e) ? ERR_ABORTED : e;
237239
}
238240
}
239241
}

0 commit comments

Comments
 (0)