Skip to content

Commit

Permalink
chore(debug): change process code for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgoff committed Oct 2, 2024
1 parent 79683e8 commit 1875bf6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
33 changes: 14 additions & 19 deletions lib/api/client/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ if (
API_URL = `http://${process.env.DOCKER_GATEWAY_IP}:${process.env.DOCKER_GATEWAY_PORT}/api`;
}

const makeClient = () => {
return createClient({
url: API_URL,
exchanges: [cacheExchange, fetchExchange],
});
};

const { getClient } = registerUrql(makeClient);

const queryAPI = async <Query, Variables extends AnyVariables = AnyVariables>({
query,
variables,
Expand All @@ -30,24 +39,6 @@ const queryAPI = async <Query, Variables extends AnyVariables = AnyVariables>({
params.append("token", previewToken);
}

const makeClient = () => {
return createClient({
url: `${API_URL}?${params.toString()}`,
exchanges: [cacheExchange, fetchExchange],
fetchOptions: () => {
return {
next: {
revalidate: previewToken ? 0 : undefined,
},
};
},
});
};

const { getClient } = registerUrql(makeClient);

console.info("urql query");

return await getClient()
.query(query, variables)
.toPromise()
Expand All @@ -58,7 +49,11 @@ const queryAPI = async <Query, Variables extends AnyVariables = AnyVariables>({

// TODO: refresh token & rerun request if expired token error
if (result.error.networkError) {
process.exitCode = 1;
process.exitCode = -99; // so we can confirm that the exit code as seen in ArgoCD is coming from this line
console.info(result.error);
} else if (result.error) {
console.info("Some other error occurred!");
console.info(result.error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function queryAPI(query, token, previewToken, variables = {}) {
.request(query, variables, headers)
.then((data) => data)
.catch((error) => {
process.exitCode = 1;
process.exitCode = -99;
console.warn("Error in fetch.js :");
console.warn(error);
return error.response;
Expand Down

0 comments on commit 1875bf6

Please sign in to comment.