Skip to content

Commit

Permalink
ORV2-1810 Adding CorrelationId header before each API request (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnan-aot authored Dec 28, 2023
1 parent a107489 commit 9d34f01
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
51 changes: 43 additions & 8 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"react-oidc-context": "^2.3.1",
"react-router-dom": "^6.11.0",
"sass": "^1.62.1",
"uuid": "^9.0.0",
"validator": "^13.9.0"
},
"scripts": {
Expand Down
17 changes: 16 additions & 1 deletion frontend/src/common/apiManager/httpRequestHandler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import axios from "axios";
import { v4 as uuidv4 } from "uuid";
import {
applyWhenNotNullable,
getDefaultNullableVal,
getDefaultRequiredVal,
} from "../helpers/util";
import { Nullable, RequiredOrNull } from "../types/common";

// Request interceptor to add a correlationId to the header.
axios.interceptors.request.use(
function (config) {
const { headers } = config;
headers.set("x-correlation-id", uuidv4());
return config;
},
function (error) {
console.log("Unable to make a request:", error);
},
);

// Add environment variables to get the full key.
// Full key structure: oidc.user:${AUTH0_ISSUER_URL}:${AUTH0_AUDIENCE}
// Full key example:: oidc.user:https://dev.loginproxy.gov.bc.ca/auth/realms/standard:on-route-bc-direct-4598
Expand Down Expand Up @@ -135,12 +148,13 @@ export const httpGETRequestStream = (url: string) => {
return fetch(url, {
headers: {
Authorization: getAccessToken(),
"x-correlation-id": uuidv4(),
},
});
};

/**
* A HTTP GET Request for streams
* A HTTP POST Request for streams
* @param url The URL of the resource.
* @returns A Promise<Response> with the response from the API.
*/
Expand All @@ -151,6 +165,7 @@ export const httpPOSTRequestStream = (url: string, data: any) => {
headers: {
Authorization: getAccessToken(),
"Content-Type": "application/json",
"x-correlation-id": uuidv4(),
},
});
};
Expand Down

0 comments on commit 9d34f01

Please sign in to comment.