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.
- package/dist/Http/ClientError.js +6 -0
- package/dist/Http/Transport/OAuthClient.js +22 -2
- package/dist/Model/Error/ApiError.d.ts +9 -5
- package/dist/Model/Error/ApiError.js +10 -9
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/Http/ClientError.js
CHANGED
|
@@ -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
|
-
|
|
120
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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.
|
|
1
|
+
export declare const VERSION = "1.73.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "1.
|
|
1
|
+
export const VERSION = "1.73.1";
|