attlaz-client 1.73.0 → 1.74.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,12 @@ export class ClientError extends Error {
9
9
  this.httpStatus = httpErrorCode;
10
10
  }
11
11
  static fromError(error) {
12
+ // Already a ClientError (or a subclass such as ApiError) — preserve it as-is.
13
+ // Re-deriving here would discard its httpStatus, because this method inspects the
14
+ // `.status`/`.code` shape of raw transport errors, not ClientError's own fields.
15
+ if (error instanceof ClientError) {
16
+ return error;
17
+ }
12
18
  let clientError = new ClientError('Unknown error', HttpStatus.HTTP_INTERNAL_SERVER_ERROR);
13
19
  const xError = error;
14
20
  if (xError.status !== null && xError.status !== undefined) {
@@ -1,6 +1,7 @@
1
1
  import { JsonSerializable } from '../../Model/JsonSerializable.js';
2
2
  import { VERSION } from '../../version.js';
3
3
  import { ClientError } from '../ClientError.js';
4
+ import { HttpStatus } from '../HttpStatus.js';
4
5
  import { HttpClient } from '../HttpClient.js';
5
6
  import { HttpClientRequest } from '../HttpClientRequest.js';
6
7
  import { OAuthClientToken } from '../OAuthClientToken.js';
@@ -76,6 +77,18 @@ export class OAuthClient {
76
77
  this.oauthClientToken = this.tokenToOauthClientToken(rawAuthToken);
77
78
  }
78
79
  catch (e) {
80
+ if (e instanceof ClientError) {
81
+ // A refresh grant rejected by the server (4xx — the refresh token is
82
+ // expired/revoked/invalid_grant) means the session is irrecoverable and
83
+ // the user must re-authenticate. Surface it as 401 Unauthorized so
84
+ // consumers sign out and redirect to login instead of showing a generic
85
+ // error. Transient failures (network / 5xx) are rethrown unchanged so a
86
+ // hiccup doesn't force a logout.
87
+ if (e.httpStatus !== null && e.httpStatus >= 400 && e.httpStatus < 500) {
88
+ throw new ClientError('Refresh token rejected, re-authentication required', HttpStatus.HTTP_UNAUTHORIZED);
89
+ }
90
+ throw e;
91
+ }
79
92
  throw ClientError.fromError(e);
80
93
  }
81
94
  }
@@ -116,8 +129,15 @@ export class OAuthClient {
116
129
  if (signWithOauthToken && OAuthClientToken.isExpired(this.oauthClientToken)) {
117
130
  if (this.refreshTokenPromise === null) {
118
131
  this.refreshTokenPromise = this.refreshToken();
119
- await this.refreshTokenPromise;
120
- this.refreshTokenPromise = null;
132
+ try {
133
+ await this.refreshTokenPromise;
134
+ }
135
+ finally {
136
+ // Always clear, even on failure, so a single failed refresh
137
+ // doesn't poison every later request with the same rejected
138
+ // promise (e.g. after the user re-authenticates).
139
+ this.refreshTokenPromise = null;
140
+ }
121
141
  }
122
142
  else {
123
143
  await this.refreshTokenPromise;
@@ -1,10 +1,14 @@
1
- export declare class ApiError extends Error {
2
- httpStatus: number | null;
1
+ import { ClientError } from '../../Http/ClientError.js';
2
+ /**
3
+ * Domain-level error produced at the API/Endpoint boundary. Extends ClientError so a single
4
+ * `instanceof ClientError` catches both transport failures (ClientError) and API errors
5
+ * (ApiError), while adding the server's structured error fields (type/code/param).
6
+ *
7
+ * httpStatus, message and response are inherited from ClientError.
8
+ */
9
+ export declare class ApiError extends ClientError {
3
10
  type: string;
4
11
  code: string;
5
12
  param?: string | undefined;
6
- stack?: string;
7
- message: string;
8
- response: unknown;
9
13
  constructor(message: string, httpErrorCode?: number | null);
10
14
  }
@@ -1,15 +1,16 @@
1
- export class ApiError extends Error {
2
- httpStatus = null;
1
+ import { ClientError } from '../../Http/ClientError.js';
2
+ /**
3
+ * Domain-level error produced at the API/Endpoint boundary. Extends ClientError so a single
4
+ * `instanceof ClientError` catches both transport failures (ClientError) and API errors
5
+ * (ApiError), while adding the server's structured error fields (type/code/param).
6
+ *
7
+ * httpStatus, message and response are inherited from ClientError.
8
+ */
9
+ export class ApiError extends ClientError {
3
10
  type;
4
11
  code;
5
- // public message: string;
6
12
  param = undefined;
7
- stack;
8
- message;
9
- response;
10
13
  constructor(message, httpErrorCode = null) {
11
- super(message);
12
- this.message = message;
13
- this.httpStatus = httpErrorCode;
14
+ super(message, httpErrorCode);
14
15
  }
15
16
  }
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export { OAuthClient } from './Http/Transport/OAuthClient.js';
14
14
  export { OAuthClientOptions } from './Http/OAuthClientOptions.js';
15
15
  export { OAuthClientToken } from './Http/OAuthClientToken.js';
16
16
  export { ClientError } from './Http/ClientError.js';
17
+ export { ApiError } from './Model/Error/ApiError.js';
17
18
  export { HttpStatus } from './Http/HttpStatus.js';
18
19
  export { ContentTypeHelper } from './Http/ContentTypeHelper.js';
19
20
  /**
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export { OAuthClient } from './Http/Transport/OAuthClient.js';
7
7
  export { OAuthClientOptions } from './Http/OAuthClientOptions.js';
8
8
  export { OAuthClientToken } from './Http/OAuthClientToken.js';
9
9
  export { ClientError } from './Http/ClientError.js';
10
+ export { ApiError } from './Model/Error/ApiError.js';
10
11
  export { HttpStatus } from './Http/HttpStatus.js';
11
12
  export { ContentTypeHelper } from './Http/ContentTypeHelper.js';
12
13
  /**
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "1.72.0";
1
+ export declare const VERSION = "1.73.1";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.72.0";
1
+ export const VERSION = "1.73.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.73.0",
3
+ "version": "1.74.0",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",