Skip to content

Commit

Permalink
Merge branch 'v2' into v2-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Jun 20, 2024
2 parents c969d90 + f635ee2 commit 980dd5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
14 changes: 12 additions & 2 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class Client {
token?: string;
axiosInstance: AxiosInstance | undefined;
clientHeader?: string;
onTokenAccessDenied?: (error: any) => void;

public setHost(host: string): void {
this.host = host;
Expand All @@ -36,6 +37,12 @@ export class Client {
this.token = token;
}

public setOnTokenAccessDenied(
onTokenAccessDenied: (error: any) => void,
): void {
this.onTokenAccessDenied = onTokenAccessDenied;
}

public getAxiosInstance(): AxiosInstance {
if (!this.axiosInstance) {
this.axiosInstance = axios.create();
Expand All @@ -55,7 +62,7 @@ export class Client {

try {
const response = await this.getAxiosInstance().post(
`${host}/${service}`,
`${host!}/${service}`,
data.payload,
{
headers: {
Expand All @@ -71,8 +78,11 @@ export class Client {
}
return response.data;
} catch (e) {
if (e === "AccessDenied Token Error") {
this.onTokenAccessDenied?.(e);
}
console.error(
`Error in fetching ${host}/${service}: ${JSON.stringify(e, null, 2)}`,
`Error in fetching ${host!}/${service}: ${JSON.stringify(e, null, 2)}`,
);
throw e;
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/powerp.js",
"version": "2.1.0-rc.1",
"version": "2.2.0",
"description": "PowERP Javascript Client",
"module": "./dist/powerpjs.es.js",
"files": [
Expand Down

0 comments on commit 980dd5f

Please sign in to comment.