Skip to content

Commit 2b5b59e

Browse files
committed
Removing rethrown errors
1 parent 2c15c5d commit 2b5b59e

21 files changed

+348
-567
lines changed

.eslintrc.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"plugins": ["@typescript-eslint", "prettier"],
55
"extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"],
66
"rules": {
7-
"no-useless-catch": "off", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule.
7+
"no-useless-catch": "error", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule.
88
"prefer-rest-params": "off",
99
"no-constant-condition": "off",
1010
// @typescript-eslint rules
11-
"@typescript-eslint/no-empty-interface": "off",
11+
"@typescript-eslint/no-empty-interface": "warn",
1212
"@typescript-eslint/ban-types": "off",
1313
"@typescript-eslint/no-unused-vars": "error",
1414
"@typescript-eslint/no-explicit-any": "off",
@@ -161,9 +161,9 @@
161161
"@typescript-eslint/no-empty-function": "error",
162162
"@typescript-eslint/no-namespace": "off",
163163
"@typescript-eslint/no-parameter-properties": "off",
164+
164165
// eslint
165-
// eslint
166-
"brace-style": "off",
166+
"brace-style": "error",
167167
"constructor-super": "error",
168168
"curly": ["error", "multi-line"],
169169
"dot-notation": "off",
@@ -178,7 +178,7 @@
178178
"no-fallthrough": "error",
179179
"no-new-func": "off",
180180
"no-new-wrappers": "error",
181-
"no-return-await": "error",
181+
"no-return-await": "off",
182182
"no-sparse-arrays": "error",
183183
"no-template-curly-in-string": "error",
184184
"no-throw-literal": "error",

spec/content/BatchRequestContent.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,9 @@ describe("BatchRequestContent.ts", () => {
309309
it("Should return json content", async () => {
310310
const req = getCreateFolderRequestCopy();
311311
const batchReq = new BatchRequestContent([req]);
312-
try {
313-
const content = await batchReq.getContent();
314-
assert.isDefined(content.requests[0].body);
315-
assert.equal(typeof content.requests[0].body, "object");
316-
} catch (error) {
317-
throw error;
318-
}
312+
const content = await batchReq.getContent();
313+
assert.isDefined(content.requests[0].body);
314+
assert.equal(typeof content.requests[0].body, "object");
319315
});
320316

321317
it("Should return image's base64 string", async () => {
@@ -335,12 +331,8 @@ describe("BatchRequestContent.ts", () => {
335331
}),
336332
};
337333
const batchReq = new BatchRequestContent([uploadOneDriveFile]);
338-
try {
339-
const content = await batchReq.getContent();
340-
assert.isDefined(content.requests[0].body);
341-
} catch (error) {
342-
throw error;
343-
}
334+
const content = await batchReq.getContent();
335+
assert.isDefined(content.requests[0].body);
344336
});
345337
});
346338

spec/core/HTTPClient.ts

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,25 @@ describe("HTTPClient.ts", () => {
6363
});
6464

6565
it("Should execute for context object with Request instance", async () => {
66-
try {
67-
const request: Request = new Request("dummy_url", {
68-
method: "GET",
69-
});
70-
const context: Context = {
71-
request,
72-
};
73-
await httpClient.sendRequest(context);
74-
} catch (error) {
75-
throw error;
76-
}
66+
const request: Request = new Request("dummy_url", {
67+
method: "GET",
68+
});
69+
const context: Context = {
70+
request,
71+
};
72+
await httpClient.sendRequest(context);
7773
});
7874

7975
it("Should execute for context object with request uri and options", async () => {
80-
try {
81-
const url = "dummy_url";
82-
const options: FetchOptions = {
83-
method: "GET",
84-
};
85-
const context: Context = {
86-
request: url,
87-
options,
88-
};
89-
await httpClient.sendRequest(context);
90-
} catch (error) {
91-
throw error;
92-
}
76+
const url = "dummy_url";
77+
const options: FetchOptions = {
78+
method: "GET",
79+
};
80+
const context: Context = {
81+
request: url,
82+
options,
83+
};
84+
await httpClient.sendRequest(context);
9385
});
9486
});
9587
});

spec/middleware/RetryHandler.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ describe("RetryHandler.ts", function() {
148148

149149
describe("sleep", async () => {
150150
it("Should run the sleep method for 1 second", async () => {
151-
try {
152-
await retryHandler["sleep"](1);
153-
} catch (error) {
154-
throw error;
155-
}
151+
await retryHandler["sleep"](1);
156152
});
157153
});
158154

spec/middleware/RetryHandlerOptions.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ import { RetryHandlerOptions, ShouldRetry } from "../../src/middleware/options/R
1212
describe("RetryHandlerOptions.ts", () => {
1313
describe("Constructor", () => {
1414
it("Should use default values if not given", () => {
15-
try {
16-
const options = new RetryHandlerOptions();
17-
assert.equal(options["delay"], RetryHandlerOptions["DEFAULT_DELAY"]);
18-
assert.equal(options["maxRetries"], RetryHandlerOptions["DEFAULT_MAX_RETRIES"]);
19-
assert.equal(options["shouldRetry"], RetryHandlerOptions["defaultShouldRetry"]);
20-
} catch (error) {
21-
throw error;
22-
}
15+
const options = new RetryHandlerOptions();
16+
assert.equal(options["delay"], RetryHandlerOptions["DEFAULT_DELAY"]);
17+
assert.equal(options["maxRetries"], RetryHandlerOptions["DEFAULT_MAX_RETRIES"]);
18+
assert.equal(options["shouldRetry"], RetryHandlerOptions["defaultShouldRetry"]);
2319
});
2420

2521
it("Should throw error for both delay and maxRetries are higher than the limit", () => {
@@ -83,20 +79,16 @@ describe("RetryHandlerOptions.ts", () => {
8379
});
8480

8581
it("Should accept all the given values", () => {
86-
try {
87-
const delay = 1;
88-
const maxRetries = 3;
89-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
90-
const shouldRetry: ShouldRetry = (d, a, req, o, res) => {
91-
return false;
92-
};
93-
const options = new RetryHandlerOptions(delay, maxRetries, shouldRetry);
94-
assert.equal(options.delay, delay);
95-
assert.equal(options.maxRetries, maxRetries);
96-
assert.equal(options.shouldRetry, shouldRetry);
97-
} catch (error) {
98-
throw error;
99-
}
82+
const delay = 1;
83+
const maxRetries = 3;
84+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
85+
const shouldRetry: ShouldRetry = (d, a, req, o, res) => {
86+
return false;
87+
};
88+
const options = new RetryHandlerOptions(delay, maxRetries, shouldRetry);
89+
assert.equal(options.delay, delay);
90+
assert.equal(options.maxRetries, maxRetries);
91+
assert.equal(options.shouldRetry, shouldRetry);
10092
});
10193
});
10294

spec/tasks/PageIterator.ts

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -75,84 +75,56 @@ describe("PageIterator.ts", () => {
7575
describe("iterate", () => {
7676
it("Should iterate over a complete collection without nextLink", async () => {
7777
const pageIterator = new PageIterator(client, getPageCollection(), truthyCallback);
78-
try {
79-
await pageIterator.iterate();
80-
assert.isTrue(pageIterator.isComplete());
81-
} catch (error) {
82-
throw error;
83-
}
78+
await pageIterator.iterate();
79+
assert.isTrue(pageIterator.isComplete());
8480
});
8581

8682
it("Should not iterate over an empty collection", async () => {
8783
const pageIterator = new PageIterator(client, getEmptyPageCollection(), truthyCallback);
8884
halfWayCallbackCounter = 1;
89-
try {
90-
await pageIterator.iterate();
91-
assert.equal(halfWayCallbackCounter, 1);
92-
} catch (error) {
93-
throw error;
94-
}
85+
await pageIterator.iterate();
86+
assert.equal(halfWayCallbackCounter, 1);
9587
});
9688

9789
it("Should break in the middle way", async () => {
9890
const pageIterator = new PageIterator(client, getPageCollection(), halfWayCallback);
9991
halfWayCallbackCounter = 5;
100-
try {
101-
await pageIterator.iterate();
102-
assert.isFalse(pageIterator.isComplete());
103-
} catch (error) {
104-
throw error;
105-
}
92+
await pageIterator.iterate();
93+
assert.isFalse(pageIterator.isComplete());
10694
});
10795
});
10896

10997
describe("iterationHelper", () => {
11098
it("Should return true for empty collection with next link", () => {
11199
const pageIterator = new PageIterator(client, getEmptyPageCollectionWithNext(), truthyCallback);
112-
try {
113-
const advance = pageIterator["iterationHelper"]();
114-
assert.isTrue(advance);
115-
} catch (error) {
116-
throw error;
117-
}
100+
const advance = pageIterator["iterationHelper"]();
101+
assert.isTrue(advance);
118102
});
119103
});
120104

121105
describe("resume", () => {
122106
it("Should start from the place where it left the iteration", async () => {
123107
const pageIterator = new PageIterator(client, getPageCollection(), halfWayCallback);
124108
halfWayCallbackCounter = 5;
125-
try {
126-
await pageIterator.iterate();
127-
assert.isFalse(pageIterator.isComplete());
128-
await pageIterator.resume();
129-
assert.isTrue(pageIterator.isComplete());
130-
} catch (error) {
131-
throw error;
132-
}
109+
await pageIterator.iterate();
110+
assert.isFalse(pageIterator.isComplete());
111+
await pageIterator.resume();
112+
assert.isTrue(pageIterator.isComplete());
133113
});
134114
});
135115

136116
describe("isComplete", () => {
137117
it("Should return false for incomplete iteration", async () => {
138118
const pageIterator = new PageIterator(client, getPageCollection(), halfWayCallback);
139119
halfWayCallbackCounter = 5;
140-
try {
141-
await pageIterator.iterate();
142-
assert.isFalse(pageIterator.isComplete());
143-
} catch (error) {
144-
throw error;
145-
}
120+
await pageIterator.iterate();
121+
assert.isFalse(pageIterator.isComplete());
146122
});
147123

148124
it("Should return true for complete iteration", async () => {
149125
const pageIterator = new PageIterator(client, getPageCollection(), truthyCallback);
150-
try {
151-
await pageIterator.iterate();
152-
assert.isTrue(pageIterator.isComplete());
153-
} catch (error) {
154-
throw error;
155-
}
126+
await pageIterator.iterate();
127+
assert.isTrue(pageIterator.isComplete());
156128
});
157129
});
158130
});

src/Client.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ export class Client {
6060
* @returns The Client instance
6161
*/
6262
public static initWithMiddleware(clientOptions: ClientOptions): Client {
63-
try {
64-
return new Client(clientOptions);
65-
} catch (error) {
66-
throw error;
67-
}
63+
return new Client(clientOptions);
6864
}
6965

7066
/**
@@ -74,11 +70,7 @@ export class Client {
7470
* @param {ClientOptions} clientOptions - The options to instantiate the client object
7571
*/
7672
private constructor(clientOptions: ClientOptions) {
77-
try {
78-
validatePolyFilling();
79-
} catch (error) {
80-
throw error;
81-
}
73+
validatePolyFilling();
8274
for (const key in clientOptions) {
8375
if (Object.prototype.hasOwnProperty.call(clientOptions, key)) {
8476
this.config[key] = clientOptions[key];

0 commit comments

Comments
 (0)