Commit 74a030c2 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: properly detect Supabase error responses in shop/achievements APIs

Check status code and absence of error 'code' key to distinguish
real data arrays from PostgREST error objects.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent d5f6e380
......@@ -19,7 +19,7 @@ if ($category) {
}
$achRes = supabase_rest('GET', $endpoint, [], $token);
$achievements = (isset($achRes['data']) && is_array($achRes['data'])) ? $achRes['data'] : [];
$achievements = ($achRes['status'] === 200 && is_array($achRes['data']) && !isset($achRes['data']['code'])) ? $achRes['data'] : [];
if (!empty($achievements)) {
$unlockedRes = supabase_rest('GET', 'player_achievements?select=achievement_id,unlocked_at', [], $token);
......
......@@ -17,7 +17,7 @@ if ($method === 'GET') {
$category = $_GET['category'] ?? 'boards';
$res = supabase_rest('GET', "shop_items?category=eq.{$category}&select=*&order=price.asc", [], $token);
$items = (isset($res['data']) && is_array($res['data'])) ? $res['data'] : [];
$items = ($res['status'] === 200 && is_array($res['data']) && !isset($res['data']['code'])) ? $res['data'] : [];
if (!empty($items)) {
$ownedRes = supabase_rest('GET', 'user_items?select=item_id', [], $token);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment