@forge/kvs 1.4.1-next.0 → 1.5.0-next.1

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.
@@ -123,12 +123,18 @@ describe('KVS', () => {
123
123
  await expect(sut.get('foo')).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 500, statusText: 'Internal Server Error', traceId }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
124
124
  });
125
125
  it('should handle non-json response even though status is ok', async () => {
126
- const response = new Response('Some non JSON response that will fail to parse', {
126
+ const responseText = 'Text that will fail to parse';
127
+ const response = new Response(responseText, {
127
128
  status: 200,
128
- headers: { 'x-trace-id': traceId }
129
+ statusText: 'OK',
130
+ headers: { 'x-trace-id': traceId, 'content-length': responseText.length.toString() }
129
131
  });
130
132
  const { sut } = prepare(response);
131
- await expect(sut.get('foo')).rejects.toMatchError(new errors_1.ForgeKvsError('Unexpected error. Response was not valid JSON: Some non JSON response that will fail to parse'));
133
+ await expect(sut.get('foo')).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 200, statusText: 'OK', traceId }, {
134
+ code: 'UNKNOWN_ERROR',
135
+ message: 'Unexpected error in Forge KVS API. Response was not valid JSON',
136
+ context: { contentLength: responseText.length.toString() }
137
+ }));
132
138
  });
133
139
  it('should getSecret correctly', async () => {
134
140
  const response = new Response(JSON.stringify({ key: 'foo', value: 'bar' }), {
@@ -1 +1 @@
1
- {"version":3,"file":"storage-api.d.ts","sourceRoot":"","sources":["../src/storage-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EACL,SAAS,EACT,UAAU,EACV,WAAW,EAGX,SAAS,EAGT,cAAc,EACf,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,kBAAkB,EAElB,eAAe,EACf,eAAe,EAEf,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAEhB,kBAAkB,EAElB,gBA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AAI,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC;IAQ3D,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IAQ3D,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAQ9D,QAAQ,CAAC,CAAC,EAAE,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAI7D,iBAAiB;YAWjB,OAAO;IA6CrB,OAAO,CAAC,kBAAkB;IAyB1B,OAAO,CAAC,kBAAkB;CAgB3B"}
@@ -126,12 +126,20 @@ class StorageApi {
126
126
  if (responseType === ResponseType.OPTIONAL && !responseText) {
127
127
  return undefined;
128
128
  }
129
- try {
130
- return JSON.parse(responseText);
131
- }
132
- catch (error) {
133
- throw new errors_1.ForgeKvsError(`Unexpected error. Response was not valid JSON: ${responseText}`);
129
+ const parsedBody = (0, error_handling_1.safeGetParsedBody)(responseText);
130
+ if (parsedBody === undefined) {
131
+ const details = {
132
+ status: response.status,
133
+ statusText: response.statusText,
134
+ traceId: (0, error_handling_1.extractTraceId)(response)
135
+ };
136
+ throw new errors_1.ForgeKvsAPIError(details, {
137
+ code: 'UNKNOWN_ERROR',
138
+ message: 'Unexpected error in Forge KVS API. Response was not valid JSON',
139
+ context: { contentLength: response.headers.get('content-length') }
140
+ });
134
141
  }
142
+ return parsedBody;
135
143
  }
136
144
  processGetResponse(response, options) {
137
145
  if (response && options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/kvs",
3
- "version": "1.4.1-next.0",
3
+ "version": "1.5.0-next.1",
4
4
  "description": "Forge Key Value Store SDK",
5
5
  "author": "Atlassian",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",