Skip to content

Commit

Permalink
Merge pull request #47 from 0Nom4D/api_errors
Browse files Browse the repository at this point in the history
Handling Bungie API Errors
  • Loading branch information
0Nom4D authored Dec 18, 2023
2 parents 1644073 + 389f048 commit f33b9c8
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 89 deletions.
8 changes: 7 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="guardian_dock"
android:label="Guardian Dock"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down Expand Up @@ -30,4 +30,10 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>
</manifest>
9 changes: 9 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,13 @@
DEVELOPMENT_TEAM = 6MURAC78AD;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Guardian Dock";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.games";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.1;
PRODUCT_BUNDLE_IDENTIFIER = dock.guardian.guardianDock;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -661,10 +664,13 @@
DEVELOPMENT_TEAM = 6MURAC78AD;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Guardian Dock";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.games";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.1;
PRODUCT_BUNDLE_IDENTIFIER = dock.guardian.guardianDock;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -687,10 +693,13 @@
DEVELOPMENT_TEAM = 6MURAC78AD;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "Guardian Dock";
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.games";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.1;
PRODUCT_BUNDLE_IDENTIFIER = dock.guardian.guardianDock;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
55 changes: 29 additions & 26 deletions ios/Runner/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--Flutter View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="FlutterViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22131"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Flutter View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="FlutterViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-16" y="-40"/>
</scene>
</scenes>
</document>
106 changes: 55 additions & 51 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Guardian Dock</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>guardian_dock</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Guardian Dock</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>guardian_dock</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIStatusBarStyle</key>
<string></string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
4 changes: 3 additions & 1 deletion lib/api/client_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class ApiClient {
final path = Uri.https(ApiClient.baseUrl, 'Platform/Destiny2/Manifest');
final response = await client.get(path, headers: headers);

if (response.statusCode >= 400) {
if (response.statusCode == 503) {
throw const HttpException("Unable to load data from Bungie. Bungie.net servers are down for maintenance.");
} else if (response.statusCode >= 400) {
throw HttpException(response.body);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/api/rss.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class Rss {
final path = Uri.https(ApiClient.baseUrl, "Platform/Content/Rss/NewsArticles/$pagination", {"includebody": "true", "lc": locale});
final response = await _client.client.get(path, headers: _client.headers);

if (response.statusCode >= 400) {
if (response.statusCode == 503) {
throw const HttpException("Unable to load data from Bungie. Bungie.net servers are down for maintenance.");
} else if (response.statusCode >= 400) {
throw HttpException(response.body);
}
return List<NewsArticle>.from(jsonDecode(utf8.decode(response.bodyBytes))['Response']['NewsArticles'].map((account) => NewsArticle.fromJson(account)));
Expand Down
4 changes: 3 additions & 1 deletion lib/api/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class Search {
body: jsonEncode({ "displayNamePrefix": displayNamePrefix })
);

if (response.statusCode >= 400) {
if (response.statusCode == 503) {
throw const HttpException("Unable to load data from Bungie. Bungie.net servers are down for maintenance.");
} else if (response.statusCode >= 400) {
throw HttpException(response.body);
}
return List<BungieAccountData>.from(jsonDecode(utf8.decode(response.bodyBytes))['Response']['searchResults'].map((account) => BungieAccountData.fromJson(account)));
Expand Down
7 changes: 4 additions & 3 deletions lib/src/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ const ColorScheme appScheme = ColorScheme(

class AppTheme {
static final ThemeData defaultTheme = ThemeData(
fontFamily: 'NeueHaasDisplay',
scaffoldBackgroundColor: appScheme.background,
colorScheme: appScheme
fontFamily: 'NeueHaasDisplay',
scaffoldBackgroundColor: appScheme.background,
colorScheme: appScheme,
useMaterial3: true
);
}
15 changes: 12 additions & 3 deletions lib/src/views/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';

import 'package:guardian_dock/src/widgets/persistent_search_bar.dart';
import 'package:guardian_dock/src/widgets/maintenance_error.dart';
import 'package:guardian_dock/src/widgets/rss/rss_news_feed.dart';
import 'package:guardian_dock/src/widgets/custom_appbar.dart';
import 'package:guardian_dock/api/models/news_article.dart';
Expand All @@ -18,7 +19,6 @@ class HomeView extends StatefulWidget {
class _HomeViewState extends State<HomeView> {
List<NewsArticle> fetchedArticles = [];
bool isLoadingNewsArticle = false;
late Future<void> future;

Future<void> getManifest() async => await GetIt.I<ApiClient>().getManifest();

Expand All @@ -28,14 +28,13 @@ class _HomeViewState extends State<HomeView> {

@override
void initState() {
future = Future.wait([getNewsArticles(), getManifest()]);
super.initState();
}

@override
Widget build(BuildContext context) {
return FutureBuilder(
future: future,
future: Future.wait([getNewsArticles(), getManifest()]),
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
Expand All @@ -46,6 +45,16 @@ class _HomeViewState extends State<HomeView> {
),
)
);
} else if (snapshot.hasError) {
return Scaffold(
body: MaintenanceError(
error: snapshot.error,
onReload: () {
setState(() {});
Future.delayed(const Duration(seconds: 5));
},
)
);
}
return Scaffold(
resizeToAvoidBottomInset: false,
Expand Down
Loading

0 comments on commit f33b9c8

Please sign in to comment.