Skip to content

Commit 4d2cd23

Browse files
committed
Removing rethrown errors
1 parent 2b5b59e commit 4d2cd23

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

.eslintrc.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"rules": {
77
"no-useless-catch": "error", //TODO- Remove the unnecessary try-catch lines used and enable no-useless-catch rule.
88
"prefer-rest-params": "off",
9-
"no-constant-condition": "off",
9+
"no-constant-condition": "error",
1010
// @typescript-eslint rules
1111
"@typescript-eslint/no-empty-interface": "warn",
1212
"@typescript-eslint/ban-types": "off",
@@ -161,8 +161,18 @@
161161
"@typescript-eslint/no-empty-function": "error",
162162
"@typescript-eslint/no-namespace": "off",
163163
"@typescript-eslint/no-parameter-properties": "off",
164-
164+
"@typescript-eslint/no-array-constructor": "error",
165165
// eslint
166+
// "sort-imports": [
167+
// "error",
168+
// {
169+
// "ignoreCase": false,
170+
// "ignoreDeclarationSort": false,
171+
// "ignoreMemberSort": false,
172+
// "memberSyntaxSortOrder": ["none", "all", "multiple", "single"],
173+
// "allowSeparatedGroups": false
174+
// }
175+
// ],
166176
"brace-style": "error",
167177
"constructor-super": "error",
168178
"curly": ["error", "multi-line"],

src/GraphResponseHandler.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,21 @@ export class GraphResponseHandler {
161161
* @returns The parsed response
162162
*/
163163
public static async getResponse(rawResponse: Response, responseType?: ResponseType, callback?: GraphRequestCallback): Promise<any> {
164-
try {
165-
if (responseType === ResponseType.RAW) {
166-
return Promise.resolve(rawResponse);
167-
} else {
168-
const response = await GraphResponseHandler.convertResponse(rawResponse, responseType);
169-
if (rawResponse.ok) {
170-
// Status Code 2XX
171-
if (typeof callback === "function") {
172-
callback(null, response);
173-
} else {
174-
return response;
175-
}
164+
if (responseType === ResponseType.RAW) {
165+
return Promise.resolve(rawResponse);
166+
} else {
167+
const response = await GraphResponseHandler.convertResponse(rawResponse, responseType);
168+
if (rawResponse.ok) {
169+
// Status Code 2XX
170+
if (typeof callback === "function") {
171+
callback(null, response);
176172
} else {
177-
// NOT OK Response
178-
throw response;
173+
return response;
179174
}
175+
} else {
176+
// NOT OK Response
177+
throw response;
180178
}
181-
} catch (error) {
182-
throw error;
183179
}
184180
}
185181
}

src/HTTPClient.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,13 @@ export class HTTPClient {
7979
* @returns A promise that resolves to the Context
8080
*/
8181
public async sendRequest(context: Context): Promise<Context> {
82-
try {
83-
if (typeof context.request === "string" && context.options === undefined) {
84-
const error = new Error();
85-
error.name = "InvalidRequestOptions";
86-
error.message = "Unable to execute the middleware, Please provide valid options for a request";
87-
throw error;
88-
}
89-
await this.middleware.execute(context);
90-
return context;
91-
} catch (error) {
82+
if (typeof context.request === "string" && context.options === undefined) {
83+
const error = new Error();
84+
error.name = "InvalidRequestOptions";
85+
error.message = "Unable to execute the middleware, Please provide valid options for a request";
9286
throw error;
9387
}
88+
await this.middleware.execute(context);
89+
return context;
9490
}
9591
}

src/browser/ImplicitMSALAuthenticationProvider.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,8 @@ export class ImplicitMSALAuthenticationProvider implements AuthenticationProvide
8282
return authResponse.accessToken;
8383
} catch (error) {
8484
if (error.name === "InteractionRequiredAuthError") {
85-
try {
86-
const authResponse = await this.msalApplication.acquireTokenPopup(tokenRequest);
87-
return authResponse.accessToken;
88-
} catch (error) {
89-
throw error;
90-
}
85+
const authResponse = await this.msalApplication.acquireTokenPopup(tokenRequest);
86+
return authResponse.accessToken;
9187
} else {
9288
throw error;
9389
}

src/tasks/LargeFileUploadTask.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export class LargeFileUploadTask {
215215
* @returns The promise resolves to uploaded response
216216
*/
217217
public async upload(): Promise<any> {
218+
// eslint-disable-next-line no-constant-condition
218219
while (true) {
219220
const nextRange = this.getNextRange();
220221
if (nextRange.maxValue === -1) {

0 commit comments

Comments
 (0)