Skip to content

Commit

Permalink
Reinsert token in cypress scripts. Re-add some lost error handling (#591
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mcanoy authored Mar 11, 2022
1 parent a663aef commit de46f78
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
16 changes: 16 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ Cypress.Commands.add(
}).then(resp => {
expect(resp.status).to.eq(200);
const jwt = resp.body;
const currentTime = new Date();
const accessTokenExpiry = new Date(
currentTime.getTime() + jwt.expires_in * 100000
).toISOString();
const refreshTokenExpiry = new Date(
currentTime.getTime() + jwt.refresh_expires_in * 100000
).toISOString();

var elToken = {
accessToken: jwt.access_token,
accessTokenExpiry: accessTokenExpiry,
refreshToken: jwt.refresh_token,
refreshTokenExpiry: refreshTokenExpiry,
};

window.localStorage.setItem('token', JSON.stringify(elToken));

window.localStorage.setItem('e2e_access_token', jwt.access_token);
window.localStorage.setItem('e2e_refresh_token', jwt.refresh_token);
Expand Down
9 changes: 3 additions & 6 deletions src/packages/api_v1_sdk/apiv1_category_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import {
CategoryFilter,
CategorySortOrder,
} from '../../services/category_service/category_service';
import { handleAxiosResponseErrors } from './http_error_handlers';
import { EngagementJsonSerializer } from '../../serializers/engagement/engagement_json_serializer';
import { getApiV1HttpClient } from './client';
import { CategoryWithCount } from '../../schemas/engagement_category';
import { ConsoleLogger } from '../../utilities/logger/loggers';
import { LogVerbosity } from '../../utilities/logger/logger';

export class Apiv1CategoryService implements CategoryService {
private get axios() {
Expand Down Expand Up @@ -73,11 +74,7 @@ export class Apiv1CategoryService implements CategoryService {
);
return serializedCategories;
} catch (e) {
if (e.isAxiosError) {
handleAxiosResponseErrors(e);
} else {
throw e;
}
ConsoleLogger(LogVerbosity.error).error("fetch category failure", e);
}
}
}
13 changes: 13 additions & 0 deletions src/packages/api_v1_sdk/http_error_handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { LogVerbosity } from "../../utilities/logger/logger";
import { ConsoleLogger } from "../../utilities/logger/loggers";

interface AxiosError {
response: {
status: number;
};
}

export function handleAxiosResponseErrors(error: AxiosError) {
ConsoleLogger(LogVerbosity.error).error("Axios Error", error);
throw error;
}

0 comments on commit de46f78

Please sign in to comment.