Handle errors in nip 86 requests, upgrade nostr-editor
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
"@tiptap/suggestion": "^2.11.5",
|
||||
"@welshman/lib": "workspace:*",
|
||||
"@welshman/util": "workspace:*",
|
||||
"nostr-editor-coracle-workaround": "0.0.4-pre.18",
|
||||
"nostr-editor": "^1.0.0",
|
||||
"nostr-tools": "^2.14.2",
|
||||
"tippy.js": "^6.3.7"
|
||||
},
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import {postJson} from "@welshman/lib"
|
||||
import {SignedEvent} from "./Events.js"
|
||||
import {makeHttpAuthHeader} from "./Nip98.js"
|
||||
|
||||
@@ -28,14 +27,30 @@ export type ManagementRequest = {
|
||||
params: string[]
|
||||
}
|
||||
|
||||
export const sendManagementRequest = (
|
||||
export type ManagementResponse = {
|
||||
result?: any
|
||||
error?: string
|
||||
}
|
||||
|
||||
export const sendManagementRequest = async (
|
||||
url: string,
|
||||
request: ManagementRequest,
|
||||
authEvent: SignedEvent,
|
||||
) =>
|
||||
postJson(url, request, {
|
||||
headers: {
|
||||
"Content-Type": "application/nostr+json+rpc",
|
||||
Authorization: makeHttpAuthHeader(authEvent),
|
||||
},
|
||||
})
|
||||
): Promise<ManagementResponse> => {
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(request),
|
||||
headers: {
|
||||
"Content-Type": "application/nostr+json+rpc",
|
||||
Authorization: makeHttpAuthHeader(authEvent),
|
||||
},
|
||||
})
|
||||
|
||||
return await res.json()
|
||||
} catch (e) {
|
||||
const msg = "Failed to send management request"
|
||||
console.log(msg, ":", e)
|
||||
return {error: "failed to send management request"}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user