@simpleplatform/sdk 3.0.2 → 3.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.
@@ -209,21 +209,22 @@ function createDataRequestId() {
209
209
  return `space-data-${Math.random().toString(36).slice(2)}`;
210
210
  }
211
211
  function readGraphQLErrorMessage(error, errors) {
212
+ const firstError = Array.isArray(errors) ? errors[0] : undefined;
213
+ const details = firstError && typeof firstError === 'object'
214
+ ? firstError
215
+ : undefined;
216
+ // The host always sends `error` beside `errors`, and `error` holds only the
217
+ // top-level messages. The text a person can act on is under `extensions`,
218
+ // so it is read first.
219
+ const issue = details?.extensions?.issues?.[0]?.message;
220
+ if (typeof issue === 'string' && issue)
221
+ return issue;
222
+ const detail = details?.extensions?.details?.message;
223
+ if (typeof detail === 'string' && detail)
224
+ return detail;
212
225
  if (typeof error === 'string' && error)
213
226
  return error;
214
- if (Array.isArray(errors)) {
215
- const firstError = errors[0];
216
- if (firstError && typeof firstError === 'object') {
217
- const details = firstError;
218
- const issue = details.extensions?.issues?.[0]?.message;
219
- if (typeof issue === 'string' && issue)
220
- return issue;
221
- const message = details.extensions?.details?.message;
222
- if (typeof message === 'string' && message)
223
- return message;
224
- if (typeof details.message === 'string' && details.message)
225
- return details.message;
226
- }
227
- }
227
+ if (typeof details?.message === 'string' && details.message)
228
+ return details.message;
228
229
  return 'GraphQL request failed.';
229
230
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simpleplatform/sdk",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "Simple Platform Typescript SDK",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://docs.simple.dev",