mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-05-08 02:37:59 +00:00
fix publish
This commit is contained in:
parent
9415e221f3
commit
3615a6e873
@ -938,6 +938,33 @@ export async function getLTCBalance() {
|
|||||||
} else throw new Error("Onable to get LTC balance");
|
} else throw new Error("Onable to get LTC balance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function parseErrorResponse(response, defaultMessage = "Request failed") {
|
||||||
|
let message = defaultMessage;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Attempt to parse JSON
|
||||||
|
const json = await response.json();
|
||||||
|
if (json?.message) {
|
||||||
|
message = json.message;
|
||||||
|
} else {
|
||||||
|
// If JSON exists but no `message` field, include full JSON string
|
||||||
|
message = JSON.stringify(json);
|
||||||
|
}
|
||||||
|
} catch (jsonError) {
|
||||||
|
try {
|
||||||
|
// Fallback to plain text
|
||||||
|
const text = await response.text();
|
||||||
|
message = text || response.statusText || message;
|
||||||
|
} catch (textError) {
|
||||||
|
// Fallback to statusText or defaultMessage
|
||||||
|
message = response.statusText || message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const processTransactionVersion2Chat = async (body: any, customApi) => {
|
const processTransactionVersion2Chat = async (body: any, customApi) => {
|
||||||
// const validApi = await findUsableApi();
|
// const validApi = await findUsableApi();
|
||||||
const url = await createEndpoint(
|
const url = await createEndpoint(
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
isUsingLocal,
|
isUsingLocal,
|
||||||
createBuyOrderTx,
|
createBuyOrderTx,
|
||||||
performPowTask,
|
performPowTask,
|
||||||
|
parseErrorResponse,
|
||||||
} from "../background";
|
} from "../background";
|
||||||
import { getNameInfo } from "../backgroundFunctions/encryption";
|
import { getNameInfo } from "../backgroundFunctions/encryption";
|
||||||
import { showSaveFilePicker } from "../components/Apps/useQortalMessageListener";
|
import { showSaveFilePicker } from "../components/Apps/useQortalMessageListener";
|
||||||
@ -634,6 +635,9 @@ export const publishQDNResource = async (
|
|||||||
if (data.identifier == null) {
|
if (data.identifier == null) {
|
||||||
identifier = "default";
|
identifier = "default";
|
||||||
}
|
}
|
||||||
|
if (data.fileId) {
|
||||||
|
data64 = await getFileFromContentScript(data.fileId);
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
data.encrypt &&
|
data.encrypt &&
|
||||||
(!data.publicKeys ||
|
(!data.publicKeys ||
|
||||||
@ -644,9 +648,7 @@ export const publishQDNResource = async (
|
|||||||
if (!data.encrypt && data.service.endsWith("_PRIVATE")) {
|
if (!data.encrypt && data.service.endsWith("_PRIVATE")) {
|
||||||
throw new Error("Only encrypted data can go into private services");
|
throw new Error("Only encrypted data can go into private services");
|
||||||
}
|
}
|
||||||
if (data.fileId) {
|
|
||||||
data64 = await getFileFromContentScript(data.fileId);
|
|
||||||
}
|
|
||||||
if (data.encrypt) {
|
if (data.encrypt) {
|
||||||
try {
|
try {
|
||||||
const resKeyPair = await getKeyPair();
|
const resKeyPair = await getKeyPair();
|
||||||
@ -683,9 +685,7 @@ export const publishQDNResource = async (
|
|||||||
);
|
);
|
||||||
const { accepted } = resPermission;
|
const { accepted } = resPermission;
|
||||||
if (accepted) {
|
if (accepted) {
|
||||||
if (data.fileId && !data.encrypt) {
|
|
||||||
data64 = await getFileFromContentScript(data.fileId);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const resPublish = await publishData({
|
const resPublish = await publishData({
|
||||||
registeredName: encodeURIComponent(name),
|
registeredName: encodeURIComponent(name),
|
||||||
@ -971,7 +971,10 @@ export const voteOnPoll = async (data, isFromExtension) => {
|
|||||||
try {
|
try {
|
||||||
const url = await createEndpoint(`/polls/${encodeURIComponent(pollName)}`);
|
const url = await createEndpoint(`/polls/${encodeURIComponent(pollName)}`);
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
if (!response.ok) throw new Error("Failed to fetch poll");
|
if (!response.ok){
|
||||||
|
const errorMessage = await parseErrorResponse(response, "Failed to fetch poll");
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
pollInfo = await response.json();
|
pollInfo = await response.json();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -979,6 +982,7 @@ export const voteOnPoll = async (data, isFromExtension) => {
|
|||||||
throw new Error(errorMsg);
|
throw new Error(errorMsg);
|
||||||
}
|
}
|
||||||
if (!pollInfo || pollInfo.error) {
|
if (!pollInfo || pollInfo.error) {
|
||||||
|
|
||||||
const errorMsg = (pollInfo && pollInfo.message) || "Poll not found";
|
const errorMsg = (pollInfo && pollInfo.message) || "Poll not found";
|
||||||
throw new Error(errorMsg);
|
throw new Error(errorMsg);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user