oauth2-cli 2.0.1 → 2.0.3

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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [2.0.3](https://github.com/battis/oauth2-cli/compare/oauth2-cli/2.0.2...oauth2-cli/2.0.3) (2026-03-31)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * include request info with bad response ([508ff58](https://github.com/battis/oauth2-cli/commit/508ff5872ae0fdfd6674a507f1d713890818cf6c))
11
+
12
+ ## [2.0.2](https://github.com/battis/oauth2-cli/compare/oauth2-cli/2.0.1...oauth2-cli/2.0.2) (2026-03-27)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * catch bad response earlier ([a47d977](https://github.com/battis/oauth2-cli/commit/a47d9774194c5cdda1c03972c7183837c88d20c1))
18
+
5
19
  ## [2.0.1](https://github.com/battis/oauth2-cli/compare/oauth2-cli/2.0.0...oauth2-cli/2.0.1) (2026-03-27)
6
20
 
7
21
 
package/dist/Client.d.ts CHANGED
@@ -124,6 +124,7 @@ export declare class Client<C extends Credentials = Credentials> extends EventEm
124
124
  * server
125
125
  */
126
126
  protected prepareRequest(...args: PreparedRequest): Promise<PreparedRequest>;
127
+ private throwNotOkResponse;
127
128
  /**
128
129
  * Available hook to manipulate the complete response from the server before
129
130
  * processing it
package/dist/Client.js CHANGED
@@ -256,17 +256,31 @@ export class Client extends EventEmitter {
256
256
  async requestRaw(url, method = 'GET', body, headers = {}, dPoPOptions) {
257
257
  url = new URL(url, this.base_url || this.credentials.issuer);
258
258
  url = requestish.URL.from(requestish.URLSearchParams.appendTo(url, requestish.URLSearchParams.merge(this.inject?.search, url.searchParams)));
259
- const request = async () => await OpenIDClient.fetchProtectedResource(...(await this.prepareRequest(await this.getConfiguration(), (await this.getToken()).access_token, url, method, await requestish.Body.from(body), requestish.Headers.merge(this.inject?.headers, headers), dPoPOptions)));
259
+ headers = requestish.Headers.merge(this.inject?.headers, headers);
260
+ body = await requestish.Body.from(body);
261
+ const request = async () => await OpenIDClient.fetchProtectedResource(...(await this.prepareRequest(await this.getConfiguration(), (await this.getToken()).access_token, url, method, body, headers, dPoPOptions)));
260
262
  try {
261
263
  return this.prepareResponse(await request());
262
264
  }
263
- catch (cause) {
264
- if (Error.isError(cause) && 'status' in cause && cause.status === 401) {
265
+ catch (error) {
266
+ if (Error.isError(error) && 'status' in error && error.status === 401) {
265
267
  await this.authorize();
266
268
  return this.prepareResponse(await request());
267
269
  }
268
270
  else {
269
- throw new Error(`${this.name} request failed`, { cause });
271
+ throw new Error(`${this.name} request failed`, {
272
+ cause: {
273
+ request: {
274
+ method,
275
+ url,
276
+ headers: headers
277
+ ? Object.fromEntries(headers.entries())
278
+ : undefined,
279
+ body
280
+ },
281
+ error
282
+ }
283
+ });
270
284
  }
271
285
  }
272
286
  }
@@ -277,11 +291,27 @@ export class Client extends EventEmitter {
277
291
  async prepareRequest(...args) {
278
292
  return args;
279
293
  }
294
+ async throwNotOkResponse(response) {
295
+ throw new Error(`${this.name} response status not ok`, {
296
+ cause: {
297
+ response: {
298
+ ok: response.ok,
299
+ status: response.status,
300
+ statusText: response.statusText,
301
+ headers: Object.fromEntries(response.headers.entries()),
302
+ body: response.body ? `${await text(response.body)}` : undefined
303
+ }
304
+ }
305
+ });
306
+ }
280
307
  /**
281
308
  * Available hook to manipulate the complete response from the server before
282
309
  * processing it
283
310
  */
284
311
  async prepareResponse(response) {
312
+ if (!response.ok) {
313
+ await this.throwNotOkResponse(response);
314
+ }
285
315
  return response;
286
316
  }
287
317
  /**
@@ -310,17 +340,7 @@ export class Client extends EventEmitter {
310
340
  }
311
341
  }
312
342
  else {
313
- throw new Error(`${this.name} response status not ok`, {
314
- cause: {
315
- response: {
316
- ok: response.ok,
317
- status: response.status,
318
- statusText: response.statusText,
319
- headers: Object.fromEntries(response.headers.entries()),
320
- body: response.body ? `${await text(response.body)}` : undefined
321
- }
322
- }
323
- });
343
+ await this.throwNotOkResponse(response);
324
344
  }
325
345
  }
326
346
  /**
@@ -331,18 +351,18 @@ export class Client extends EventEmitter {
331
351
  * `PaginatedCollection<T>`
332
352
  */
333
353
  async request(url, method = 'GET', body, headers = {}, dPoPOptions) {
354
+ const response = await this.requestRaw(url, method, body, headers, dPoPOptions);
334
355
  try {
335
- const response = await this.requestRaw(url, method, body, headers, dPoPOptions);
336
356
  return await this.processResponse(response);
337
357
  }
338
358
  catch (error) {
339
- throw new Error(`Bad response from ${this.name}`, {
359
+ throw new Error(`${this.name} request resulted in bad response`, {
340
360
  cause: {
341
361
  request: {
342
362
  method,
343
- url: requestish.URL.toString(url),
363
+ url,
344
364
  headers: Object.fromEntries(requestish.Headers.from(headers).entries()),
345
- body
365
+ body: requestish.Body.from(body)
346
366
  },
347
367
  error
348
368
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oauth2-cli",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Acquire API access tokens via OAuth 2.0 / OpenID Connect within CLI tools",
5
5
  "homepage": "https://github.com/battis/oauth2-cli/tree/main/packages/oauth2-cli#readme",
6
6
  "repository": {