attlaz-client 1.11.11 → 1.11.14

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.
@@ -51,7 +51,9 @@ export class HttpClient {
51
51
  jsonData = JSON.parse(rawData);
52
52
  }
53
53
  catch (e) {
54
- console.error('Unable to parse response data to JSON', { statusText: httpResponse.statusText, error: e });
54
+ console.error('Unable to parse response data to JSON', {
55
+ statusText: httpResponse.statusText, error: e,
56
+ });
55
57
  }
56
58
  }
57
59
  httpResponse.body = jsonData;
@@ -61,7 +63,8 @@ export class HttpClient {
61
63
  }
62
64
  const error = ClientError.byStatus(response.status, response.statusText);
63
65
  if (error !== null && error !== undefined) {
64
- error.body = httpResponse.body;
66
+ console.log(httpResponse.body);
67
+ error.message = httpResponse.body.error.message;
65
68
  throw error;
66
69
  }
67
70
  return httpResponse;
@@ -105,11 +105,14 @@ export class OAuthClient {
105
105
  return response.body;
106
106
  }
107
107
  catch (error) {
108
- const clientError = ClientError.fromError(error);
109
- if (this.debug) {
110
- console.error('[Client] Error:', { error, clientError });
108
+ if (!(error instanceof ClientError)) {
109
+ const clientError = ClientError.fromError(error);
110
+ if (this.debug) {
111
+ console.error('[Client] Error:', { error, clientError });
112
+ }
113
+ throw clientError;
111
114
  }
112
- throw clientError;
115
+ throw error;
113
116
  }
114
117
  }
115
118
  }
@@ -1,10 +1,8 @@
1
1
  export declare class ClientError implements Error {
2
- message: string;
3
- name: string;
4
2
  code: number | null;
5
- stack: string;
6
- body: string | null;
7
- constructor(message: string, code?: number | null);
3
+ name: string;
4
+ message: string;
5
+ constructor(name: string, code?: number | null);
8
6
  static fromError(error: Error | any): ClientError;
9
7
  static byStatus(statusCode: number, statusText: string): ClientError | null;
10
8
  }
@@ -1,15 +1,18 @@
1
1
  import { HttpClient } from '../../Http/HttpClient.js';
2
2
  export class ClientError {
3
- message;
4
- name;
5
3
  code;
6
- stack;
7
- body = null;
8
- constructor(message, code = null) {
9
- this.message = message;
4
+ name;
5
+ message;
6
+ // description: string | null;
7
+ // stack: string;
8
+ // body: string | null = null;
9
+ constructor(name, code = null) {
10
+ this.name = name;
11
+ this.message = name;
10
12
  this.code = code;
11
13
  }
12
14
  static fromError(error) {
15
+ console.log(error);
13
16
  if (error.body !== undefined && error.body !== null && error.body.error !== undefined && error.body.error !== null) {
14
17
  error = error.body.error;
15
18
  }
@@ -42,7 +45,7 @@ export class ClientError {
42
45
  }
43
46
  }
44
47
  clientError.name = error.name;
45
- clientError.stack = error.stack;
48
+ // clientError.stack = error.stack;
46
49
  return clientError;
47
50
  }
48
51
  static byStatus(statusCode, statusText) {
@@ -81,13 +81,13 @@ export class Endpoint {
81
81
  * Parse data
82
82
  */
83
83
  if (requestResponse === null || requestResponse === undefined) {
84
- throw new Error('Unable to parse collection: response is empty');
84
+ throw new Error('Unable to parse collection: response is empty for action `[' + method + '] ' + action + '`');
85
85
  }
86
86
  if (!requestResponse.hasOwnProperty('data') || requestResponse.data === undefined) {
87
- throw new Error('Unable to parse collection: data is not defined');
87
+ throw new Error('Unable to parse collection: data is not defined in response from action `[' + method + '] ' + action + '`');
88
88
  }
89
89
  if (!requestResponse.hasOwnProperty('has_more') || requestResponse.has_more === undefined) {
90
- throw new Error('Unable to parse collection: hasMore is not defined');
90
+ throw new Error('Unable to parse collection: hasMore is not defined in response from action `[' + method + '] ' + action + '`');
91
91
  }
92
92
  const hasMore = Utils.isTrue(requestResponse.has_more);
93
93
  result.setData(this.parseCollection(requestResponse.data, parser), hasMore);
@@ -104,7 +104,7 @@ export class Endpoint {
104
104
  */
105
105
  // TODO: temporary check until we know the API is fully upgraded
106
106
  if (requestResponse === null || requestResponse === undefined) {
107
- throw new Error('Unable to parse object: response is empty');
107
+ throw new Error('Unable to parse object: response is empty for action `[' + method + '] ' + action + '`');
108
108
  }
109
109
  if ((requestResponse.hasOwnProperty('data') && !requestResponse.hasOwnProperty('id')) && requestResponse.data !== undefined) {
110
110
  console.error('Response for object "' + action + '" seem to still use old "data" property', { requestResponse });
@@ -3,5 +3,6 @@ import { Workspace } from '../Model/Workspace/Workspace.js';
3
3
  import { CollectionResult } from '../Model/Result/CollectionResult.js';
4
4
  export declare class WorkspaceEndpoint extends Endpoint {
5
5
  getAll(): Promise<CollectionResult<Workspace>>;
6
+ getById(workspaceId: string): Promise<Workspace | null>;
6
7
  save(workspace: Workspace): Promise<Workspace>;
7
8
  }
@@ -13,6 +13,19 @@ export class WorkspaceEndpoint extends Endpoint {
13
13
  throw e;
14
14
  }
15
15
  }
16
+ async getById(workspaceId) {
17
+ try {
18
+ const url = '/workspaces/' + workspaceId + '';
19
+ const result = await this.requestObject(url, null, Workspace.parse);
20
+ return result.getData();
21
+ }
22
+ catch (error) {
23
+ if (this.httpClient.isDebugEnabled()) {
24
+ console.error('Failed to load workspace by id: ', error);
25
+ }
26
+ throw error;
27
+ }
28
+ }
16
29
  async save(workspace) {
17
30
  try {
18
31
  const url = '/workspaces';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.11.11",
3
+ "version": "1.11.14",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",