@helia/verified-fetch 2.6.3 → 2.6.5
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.min.js +109 -44
- package/dist/src/plugins/plugin-handle-ipns-record.js +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
- package/dist/src/utils/dir-index-html.d.ts +3 -0
- package/dist/src/utils/dir-index-html.d.ts.map +1 -1
- package/dist/src/utils/dir-index-html.js +40 -17
- package/dist/src/utils/dir-index-html.js.map +1 -1
- package/dist/src/utils/parse-url-string.d.ts +4 -2
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js +15 -7
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/responses.d.ts +1 -4
- package/dist/src/utils/responses.d.ts.map +1 -1
- package/dist/src/utils/responses.js +25 -9
- package/dist/src/utils/responses.js.map +1 -1
- package/package.json +19 -19
- package/src/plugins/plugin-handle-ipns-record.ts +1 -1
- package/src/utils/dir-index-html.ts +49 -17
- package/src/utils/parse-url-string.ts +16 -7
- package/src/utils/responses.ts +27 -9
package/src/utils/responses.ts
CHANGED
|
@@ -98,17 +98,35 @@ export function notFoundResponse (url: string, body?: SupportedBodyTypes, init?:
|
|
|
98
98
|
return response
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
function isArrayOfErrors (body: unknown | Error | Error[]): body is Error[] {
|
|
102
|
+
return Array.isArray(body) && body.every(e => e instanceof Error)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function badRequestResponse (url: string, errors: Error | Error[], init?: ResponseInit): Response {
|
|
106
|
+
// stacktrace of the single error, or the stacktrace of the last error in the array
|
|
107
|
+
let stack: string | undefined
|
|
108
|
+
let convertedErrors: Array<{ message: string, stack: string }> | undefined
|
|
109
|
+
if (isArrayOfErrors(errors)) {
|
|
110
|
+
stack = errors[errors.length - 1].stack
|
|
111
|
+
convertedErrors = errors.map(e => ({ message: e.message, stack: e.stack ?? '' }))
|
|
112
|
+
} else if (errors instanceof Error) {
|
|
113
|
+
stack = errors.stack
|
|
114
|
+
convertedErrors = [{ message: errors.message, stack: errors.stack ?? '' }]
|
|
107
115
|
}
|
|
108
|
-
|
|
109
|
-
|
|
116
|
+
|
|
117
|
+
const bodyJson = JSON.stringify({
|
|
118
|
+
stack,
|
|
119
|
+
errors: convertedErrors
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const response = new Response(bodyJson, {
|
|
110
123
|
status: 400,
|
|
111
|
-
statusText: 'Bad Request'
|
|
124
|
+
statusText: 'Bad Request',
|
|
125
|
+
...(init ?? {}),
|
|
126
|
+
headers: {
|
|
127
|
+
...(init?.headers ?? {}),
|
|
128
|
+
'Content-Type': 'application/json'
|
|
129
|
+
}
|
|
112
130
|
})
|
|
113
131
|
|
|
114
132
|
setType(response, 'basic')
|