fix: allow malformed utf-8

This commit is contained in:
edde746
2025-11-05 12:36:09 +01:00
parent 0817153f4b
commit fd9ba46b7b
+11
View File
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import '../config/plex_config.dart';
import '../models/plex_library.dart';
@@ -22,6 +23,15 @@ class PlexClient {
PlexConfig config;
late final Dio _dio;
/// Custom response decoder that handles malformed UTF-8 gracefully
static String _lenientUtf8Decoder(
List<int> responseBytes,
RequestOptions options,
ResponseBody responseBody,
) {
return utf8.decode(responseBytes, allowMalformed: true);
}
PlexClient(this.config) {
_dio = Dio(
BaseOptions(
@@ -32,6 +42,7 @@ class PlexClient {
validateStatus: (status) => status != null && status < 500,
responseType: ResponseType.json,
contentType: 'application/json; charset=utf-8',
responseDecoder: _lenientUtf8Decoder,
),
);