From 5994be5ddc371228e033322f7be5d2aa0375d23b Mon Sep 17 00:00:00 2001 From: billisdead Date: Sat, 16 May 2026 12:48:22 +0200 Subject: [PATCH] fix: improve POST payload and error reporting in compose - Omit image field from content when no image is selected (sending image:[] likely fails the API's schema validation with a 400) - Extract full axios response body in the error alert so the actual API error message is visible instead of just the HTTP status line Co-Authored-By: Claude Sonnet 4.6 --- artifacts/postiz-mobile/app/(tabs)/compose.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/artifacts/postiz-mobile/app/(tabs)/compose.tsx b/artifacts/postiz-mobile/app/(tabs)/compose.tsx index c850387..c020418 100644 --- a/artifacts/postiz-mobile/app/(tabs)/compose.tsx +++ b/artifacts/postiz-mobile/app/(tabs)/compose.tsx @@ -1,5 +1,6 @@ import { Feather } from "@expo/vector-icons"; import { useQuery, useQueryClient } from "@tanstack/react-query"; +import axios from "axios"; import DateTimePicker from "@react-native-community/datetimepicker"; import * as Haptics from "expo-haptics"; import { Image } from "expo-image"; @@ -129,10 +130,15 @@ export default function ComposeScreen() { media = [{ id: uploaded.id, path: uploaded.path }]; } } + const contentItem: { content: string; image?: Array<{ id: string; path: string }> } = { + content: content.trim(), + }; + if (media.length > 0) contentItem.image = media; + const payload = { type: postNow ? "now" : "schedule", date: postNow ? new Date().toISOString() : scheduleDate.toISOString(), - content: [{ content: content.trim(), image: media }], + content: [contentItem], integrations: selectedChannels, }; await client.post("posts", payload); @@ -147,7 +153,15 @@ export default function ComposeScreen() { } catch (e: unknown) { Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error); let msg = "Could not submit post."; - if (e instanceof Error) msg += `\n${e.message}`; + if (axios.isAxiosError(e)) { + const data = e.response?.data; + const detail = data + ? (typeof data === "string" ? data : (data?.message ?? data?.error ?? JSON.stringify(data))).toString().slice(0, 300) + : e.message; + msg = `HTTP ${e.response?.status ?? "?"}: ${detail}`; + } else if (e instanceof Error) { + msg += `\n${e.message}`; + } Alert.alert("Failed", msg); } finally { setSubmitting(false);