From b148930801bfd3b542696771fae1b4caff97d735 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Thu, 4 Mar 2021 19:26:57 -0800 Subject: [PATCH] Alert image loading errors --- Localizations/Localizable.strings | 1 + View Controllers/ImageViewController.swift | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index e58b451..81867bd 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -162,6 +162,7 @@ "identities.browsing" = "Browsing"; "identities.log-out" = "Log out"; "identities.pending" = "Pending"; +"image-error.unable-to-load" = "Unable to load image"; "lists.new-list-title" = "New List Title"; "load-more" = "Load More"; "load-more.above.accessibility.post" = "Load from post above"; diff --git a/View Controllers/ImageViewController.swift b/View Controllers/ImageViewController.swift index 829875a..e6bb18d 100644 --- a/View Controllers/ImageViewController.swift +++ b/View Controllers/ImageViewController.swift @@ -7,6 +7,19 @@ import SDWebImage import UIKit import ViewModels +enum ImageError: Error { + case unableToLoad +} + +extension ImageError: LocalizedError { + var errorDescription: String? { + switch self { + case .unableToLoad: + return NSLocalizedString("image-error.unable-to-load", comment: "") + } + } +} + final class ImageViewController: UIViewController { let scrollView = UIScrollView() let imageView = SDAnimatedImageView() @@ -124,7 +137,14 @@ final class ImageViewController: UIViewController { placeholderImage = nil } - imageView.sd_setImage(with: viewModel.attachment.url, placeholderImage: placeholderImage) + imageView.sd_setImage(with: viewModel.attachment.url, + placeholderImage: placeholderImage) { _, error, _, _ in + if error != nil { + let alertItem = AlertItem(error: ImageError.unableToLoad) + + self.present(alertItem: alertItem) + } + } case .gifv: playerView.tag = viewModel.tag imageView.isHidden = true