Handle HTML errors in WgerHttpException

These need to be handled separately when the server encounters an error and
returns HTML instead of JSON.
This commit is contained in:
Roland Geider
2025-12-17 15:14:47 +01:00
parent f26267a6fb
commit 077dcaf742
32 changed files with 284 additions and 139 deletions

View File

@@ -21,10 +21,10 @@ import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:wger/core/exceptions/http_exception.dart';
import 'package:wger/core/exceptions/no_such_entry_exception.dart';
import 'package:wger/core/locator.dart';
import 'package:wger/database/ingredients/ingredients_database.dart';
import 'package:wger/exceptions/http_exception.dart';
import 'package:wger/exceptions/no_such_entry_exception.dart';
import 'package:wger/helpers/consts.dart';
import 'package:wger/models/nutrition/ingredient.dart';
import 'package:wger/models/nutrition/ingredient_image.dart';
@@ -220,7 +220,7 @@ class NutritionPlansProvider with ChangeNotifier {
if (response.statusCode >= 400) {
_plans.insert(existingPlanIndex, existingPlan);
notifyListeners();
throw WgerHttpException(response.body);
throw WgerHttpException(response);
}
//existingPlan = null;
}
@@ -263,7 +263,7 @@ class NutritionPlansProvider with ChangeNotifier {
if (response.statusCode >= 400) {
plan.meals.insert(mealIndex, existingMeal);
notifyListeners();
throw WgerHttpException(response.body);
throw WgerHttpException(response);
}
}
@@ -293,7 +293,7 @@ class NutritionPlansProvider with ChangeNotifier {
if (response.statusCode >= 400) {
meal.mealItems.insert(mealItemIndex, existingMealItem);
notifyListeners();
throw WgerHttpException(response.body);
throw WgerHttpException(response);
}
}