@sanity/client 7.21.0 → 7.22.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/index.browser.cjs +22 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +8 -1
- package/dist/index.browser.d.ts +8 -1
- package/dist/index.browser.js +22 -10
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +23 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +23 -11
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +8 -1
- package/dist/stega.browser.d.ts +8 -1
- package/dist/stega.d.cts +8 -1
- package/dist/stega.d.ts +8 -1
- package/package.json +1 -1
- package/src/http/errors.ts +41 -12
- package/src/types.ts +1 -0
- package/umd/sanityClient.js +22 -10
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.cts
CHANGED
|
@@ -861,6 +861,7 @@ export declare class ClientError extends Error {
|
|
|
861
861
|
response: ErrorProps['response']
|
|
862
862
|
statusCode: ErrorProps['statusCode']
|
|
863
863
|
responseBody: ErrorProps['responseBody']
|
|
864
|
+
traceId: ErrorProps['traceId']
|
|
864
865
|
details: ErrorProps['details']
|
|
865
866
|
constructor(res: Any, context?: HttpContext)
|
|
866
867
|
}
|
|
@@ -1417,6 +1418,7 @@ export declare interface ErrorProps {
|
|
|
1417
1418
|
response: Any
|
|
1418
1419
|
statusCode: number
|
|
1419
1420
|
responseBody: Any
|
|
1421
|
+
traceId?: string
|
|
1420
1422
|
details: Any
|
|
1421
1423
|
}
|
|
1422
1424
|
|
|
@@ -1567,7 +1569,11 @@ export declare type FitMode = 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'p
|
|
|
1567
1569
|
* @returns A formatted error message string.
|
|
1568
1570
|
* @public
|
|
1569
1571
|
*/
|
|
1570
|
-
export declare function formatQueryParseError(
|
|
1572
|
+
export declare function formatQueryParseError(
|
|
1573
|
+
error: QueryParseError,
|
|
1574
|
+
tag?: string | null,
|
|
1575
|
+
traceId?: string,
|
|
1576
|
+
): string
|
|
1571
1577
|
|
|
1572
1578
|
/** @beta */
|
|
1573
1579
|
declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
|
|
@@ -5879,6 +5885,7 @@ export declare class ServerError extends Error {
|
|
|
5879
5885
|
response: ErrorProps['response']
|
|
5880
5886
|
statusCode: ErrorProps['statusCode']
|
|
5881
5887
|
responseBody: ErrorProps['responseBody']
|
|
5888
|
+
traceId: ErrorProps['traceId']
|
|
5882
5889
|
details: ErrorProps['details']
|
|
5883
5890
|
constructor(res: Any)
|
|
5884
5891
|
}
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -861,6 +861,7 @@ export declare class ClientError extends Error {
|
|
|
861
861
|
response: ErrorProps['response']
|
|
862
862
|
statusCode: ErrorProps['statusCode']
|
|
863
863
|
responseBody: ErrorProps['responseBody']
|
|
864
|
+
traceId: ErrorProps['traceId']
|
|
864
865
|
details: ErrorProps['details']
|
|
865
866
|
constructor(res: Any, context?: HttpContext)
|
|
866
867
|
}
|
|
@@ -1417,6 +1418,7 @@ export declare interface ErrorProps {
|
|
|
1417
1418
|
response: Any
|
|
1418
1419
|
statusCode: number
|
|
1419
1420
|
responseBody: Any
|
|
1421
|
+
traceId?: string
|
|
1420
1422
|
details: Any
|
|
1421
1423
|
}
|
|
1422
1424
|
|
|
@@ -1567,7 +1569,11 @@ export declare type FitMode = 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'p
|
|
|
1567
1569
|
* @returns A formatted error message string.
|
|
1568
1570
|
* @public
|
|
1569
1571
|
*/
|
|
1570
|
-
export declare function formatQueryParseError(
|
|
1572
|
+
export declare function formatQueryParseError(
|
|
1573
|
+
error: QueryParseError,
|
|
1574
|
+
tag?: string | null,
|
|
1575
|
+
traceId?: string,
|
|
1576
|
+
): string
|
|
1571
1577
|
|
|
1572
1578
|
/** @beta */
|
|
1573
1579
|
declare type GenerateAsyncInstruction<T extends Record<string, Any> = Record<string, Any>> = (
|
|
@@ -5879,6 +5885,7 @@ export declare class ServerError extends Error {
|
|
|
5879
5885
|
response: ErrorProps['response']
|
|
5880
5886
|
statusCode: ErrorProps['statusCode']
|
|
5881
5887
|
responseBody: ErrorProps['responseBody']
|
|
5888
|
+
traceId: ErrorProps['traceId']
|
|
5882
5889
|
details: ErrorProps['details']
|
|
5883
5890
|
constructor(res: Any)
|
|
5884
5891
|
}
|
package/dist/index.browser.js
CHANGED
|
@@ -85,6 +85,7 @@ class ClientError extends Error {
|
|
|
85
85
|
response;
|
|
86
86
|
statusCode = 400;
|
|
87
87
|
responseBody;
|
|
88
|
+
traceId;
|
|
88
89
|
details;
|
|
89
90
|
constructor(res, context) {
|
|
90
91
|
const props = extractErrorProps(res, context);
|
|
@@ -95,6 +96,7 @@ class ServerError extends Error {
|
|
|
95
96
|
response;
|
|
96
97
|
statusCode = 500;
|
|
97
98
|
responseBody;
|
|
99
|
+
traceId;
|
|
98
100
|
details;
|
|
99
101
|
constructor(res) {
|
|
100
102
|
const props = extractErrorProps(res);
|
|
@@ -106,29 +108,30 @@ function extractErrorProps(res, context) {
|
|
|
106
108
|
response: res,
|
|
107
109
|
statusCode: res.statusCode,
|
|
108
110
|
responseBody: stringifyBody(body, res),
|
|
111
|
+
traceId: extractTraceId(res),
|
|
109
112
|
message: "",
|
|
110
113
|
details: void 0
|
|
111
114
|
};
|
|
112
115
|
if (!isRecord(body))
|
|
113
|
-
return props.message = httpErrorMessage(res, body)
|
|
116
|
+
return props.message = `${httpErrorMessage(res, body)}${formatTraceId(props.traceId)}`, props;
|
|
114
117
|
const error = body.error;
|
|
115
118
|
if (typeof error == "string" && typeof body.message == "string")
|
|
116
|
-
return props.message = `${error} - ${body.message}`, props;
|
|
119
|
+
return props.message = `${error} - ${body.message}${formatTraceId(props.traceId)}`, props;
|
|
117
120
|
if (typeof error != "object" || error === null)
|
|
118
|
-
return typeof error == "string" ? props.message = error : typeof body.message == "string" ? props.message = body.message : props.message = httpErrorMessage(res, body)
|
|
121
|
+
return typeof error == "string" ? props.message = `${error}${formatTraceId(props.traceId)}` : typeof body.message == "string" ? props.message = `${body.message}${formatTraceId(props.traceId)}` : props.message = `${httpErrorMessage(res, body)}${formatTraceId(props.traceId)}`, props;
|
|
119
122
|
if (isMutationError(error) || isActionError(error)) {
|
|
120
123
|
const allItems = error.items || [], items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map((item) => item.error?.description).filter(Boolean);
|
|
121
124
|
let itemsStr = items.length ? `:
|
|
122
125
|
- ${items.join(`
|
|
123
126
|
- `)}` : "";
|
|
124
127
|
return allItems.length > MAX_ITEMS_IN_ERROR_MESSAGE && (itemsStr += `
|
|
125
|
-
...and ${allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE} more`), props.message = `${error.description}${itemsStr}`, props.details = body.error, props;
|
|
128
|
+
...and ${allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE} more`), props.message = `${error.description}${formatTraceId(props.traceId)}${itemsStr}`, props.details = body.error, props;
|
|
126
129
|
}
|
|
127
130
|
if (isQueryParseError(error)) {
|
|
128
131
|
const tag = context?.options?.query?.tag;
|
|
129
|
-
return props.message = formatQueryParseError(error, tag), props.details = body.error, props;
|
|
132
|
+
return props.message = formatQueryParseError(error, tag, props.traceId), props.details = body.error, props;
|
|
130
133
|
}
|
|
131
|
-
return "description" in error && typeof error.description == "string" ? (props.message = error.description
|
|
134
|
+
return "description" in error && typeof error.description == "string" ? (props.message = `${error.description}${formatTraceId(props.traceId)}`, props.details = error, props) : (props.message = `${httpErrorMessage(res, body)}${formatTraceId(props.traceId)}`, props);
|
|
132
135
|
}
|
|
133
136
|
function isMutationError(error) {
|
|
134
137
|
return "type" in error && error.type === "mutationError" && "description" in error && typeof error.description == "string";
|
|
@@ -139,23 +142,32 @@ function isActionError(error) {
|
|
|
139
142
|
function isQueryParseError(error) {
|
|
140
143
|
return isRecord(error) && error.type === "queryParseError" && typeof error.query == "string" && typeof error.start == "number" && typeof error.end == "number";
|
|
141
144
|
}
|
|
142
|
-
function formatQueryParseError(error, tag) {
|
|
143
|
-
const { query, start, end, description } = error
|
|
145
|
+
function formatQueryParseError(error, tag, traceId) {
|
|
146
|
+
const { query, start, end, description } = error, withTraceId = traceId ? `
|
|
147
|
+
(traceId: ${traceId})` : "";
|
|
144
148
|
if (!query || typeof start > "u")
|
|
145
|
-
return `GROQ query parse error: ${description}`;
|
|
149
|
+
return `GROQ query parse error: ${description}${withTraceId}`;
|
|
146
150
|
const withTag = tag ? `
|
|
147
151
|
|
|
148
152
|
Tag: ${tag}` : "";
|
|
149
153
|
return `GROQ query parse error:
|
|
150
|
-
${codeFrame(query, { start, end }, description)}${withTag}`;
|
|
154
|
+
${codeFrame(query, { start, end }, description)}${withTag}${withTraceId}`;
|
|
151
155
|
}
|
|
152
156
|
function httpErrorMessage(res, body) {
|
|
153
157
|
const details = typeof body == "string" ? ` (${sliceWithEllipsis(body, 100)})` : "", statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
|
|
154
158
|
return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}${details}`;
|
|
155
159
|
}
|
|
160
|
+
function extractTraceId(res) {
|
|
161
|
+
const traceparent = res?.headers?.traceparent;
|
|
162
|
+
if (traceparent)
|
|
163
|
+
return traceparent.split("-")[1];
|
|
164
|
+
}
|
|
156
165
|
function stringifyBody(body, res) {
|
|
157
166
|
return (res.headers["content-type"] || "").toLowerCase().indexOf("application/json") !== -1 ? JSON.stringify(body, null, 2) : body;
|
|
158
167
|
}
|
|
168
|
+
function formatTraceId(traceId) {
|
|
169
|
+
return traceId ? ` (traceId: ${traceId})` : "";
|
|
170
|
+
}
|
|
159
171
|
function sliceWithEllipsis(str, max) {
|
|
160
172
|
return str.length > max ? `${str.slice(0, max)}\u2026` : str;
|
|
161
173
|
}
|