mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-05-07 10:17:51 +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");
|
||||
}
|
||||
|
||||
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 validApi = await findUsableApi();
|
||||
const url = await createEndpoint(
|
||||
|
@ -15,6 +15,7 @@ import {
|
||||
isUsingLocal,
|
||||
createBuyOrderTx,
|
||||
performPowTask,
|
||||
parseErrorResponse,
|
||||
} from "../background";
|
||||
import { getNameInfo } from "../backgroundFunctions/encryption";
|
||||
import { showSaveFilePicker } from "../components/Apps/useQortalMessageListener";
|
||||
@ -634,6 +635,9 @@ export const publishQDNResource = async (
|
||||
if (data.identifier == null) {
|
||||
identifier = "default";
|
||||
}
|
||||
if (data.fileId) {
|
||||
data64 = await getFileFromContentScript(data.fileId);
|
||||
}
|
||||
if (
|
||||
data.encrypt &&
|
||||
(!data.publicKeys ||
|
||||
@ -644,9 +648,7 @@ export const publishQDNResource = async (
|
||||
if (!data.encrypt && data.service.endsWith("_PRIVATE")) {
|
||||
throw new Error("Only encrypted data can go into private services");
|
||||
}
|
||||
if (data.fileId) {
|
||||
data64 = await getFileFromContentScript(data.fileId);
|
||||
}
|
||||
|
||||
if (data.encrypt) {
|
||||
try {
|
||||
const resKeyPair = await getKeyPair();
|
||||
@ -683,9 +685,7 @@ export const publishQDNResource = async (
|
||||
);
|
||||
const { accepted } = resPermission;
|
||||
if (accepted) {
|
||||
if (data.fileId && !data.encrypt) {
|
||||
data64 = await getFileFromContentScript(data.fileId);
|
||||
}
|
||||
|
||||
try {
|
||||
const resPublish = await publishData({
|
||||
registeredName: encodeURIComponent(name),
|
||||
@ -971,7 +971,10 @@ export const voteOnPoll = async (data, isFromExtension) => {
|
||||
try {
|
||||
const url = await createEndpoint(`/polls/${encodeURIComponent(pollName)}`);
|
||||
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();
|
||||
} catch (error) {
|
||||
@ -979,6 +982,7 @@ export const voteOnPoll = async (data, isFromExtension) => {
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
if (!pollInfo || pollInfo.error) {
|
||||
|
||||
const errorMsg = (pollInfo && pollInfo.message) || "Poll not found";
|
||||
throw new Error(errorMsg);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user