Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 62ab896

Browse files
authored
show special alert for FORBIDDEN graphQL errors (#2567)
1 parent 7a128a9 commit 62ab896

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

Classes/Issues/Comments/IssueCommentSectionController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,12 @@ final class IssueCommentSectionController: ListBindingSectionController<IssueCom
208208
update(animated: trueUnlessReduceMotionEnabled)
209209
generator.impactOccurred()
210210
client.react(subjectID: object.id, content: content, isAdd: isAdd) { [weak self] result in
211-
if result == nil {
211+
switch result {
212+
case .success:
212213
self?.reactionMutation = previousReaction
213214
self?.update(animated: trueUnlessReduceMotionEnabled)
215+
case .error(let error):
216+
Squawk.show(error: error)
214217
}
215218
}
216219
}

Classes/Issues/GithubClient+Issues.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,15 @@ extension GithubClient {
185185
subjectID: String,
186186
content: ReactionContent,
187187
isAdd: Bool,
188-
completion: @escaping (IssueCommentReactionViewModel?) -> Void
188+
completion: @escaping (Result<IssueCommentReactionViewModel>) -> Void
189189
) {
190190

191191
let handler: (GitHubAPI.Result<ReactionFields>) -> Void = { result in
192192
switch result {
193193
case .success(let data):
194-
completion(createIssueReactions(reactions: data))
194+
completion(.success(createIssueReactions(reactions: data)))
195195
case .failure(let error):
196-
completion(nil)
197-
Squawk.show(error: error)
196+
completion(.error(error))
198197
}
199198
}
200199

Classes/Systems/Squawk+GitHawk.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ extension Squawk {
5959
}
6060

6161
static func show(error: Error?, view: UIView? = window) {
62-
let text = error?.localizedDescription
63-
?? NSLocalizedString("Something went wrong.", comment: "")
62+
let text: String
63+
if error?.isGraphQLForbidden == true {
64+
text = NSLocalizedString(
65+
"Some repositories or organizations you browse may require Personal Access Tokens for access. You can add a PAT in Settings>Accounts.",
66+
comment: ""
67+
)
68+
} else {
69+
text = error?.localizedDescription
70+
?? NSLocalizedString("Something went wrong.", comment: "")
71+
}
6472
Squawk.shared.show(in: view, config: errorConfig(text: text))
6573
triggerHaptic()
6674
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Error+GraphQLForbidden.swift
3+
// Freetime
4+
//
5+
// Created by Ryan Nystrom on 12/29/18.
6+
// Copyright © 2018 Ryan Nystrom. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import Apollo
11+
12+
extension Error {
13+
14+
var isGraphQLForbidden: Bool {
15+
guard let error = self as? Apollo.GraphQLError else { return false }
16+
return (error["type"] as? String)?.uppercased() == "FORBIDDEN"
17+
}
18+
19+
}

Freetime.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@
302302
298BA0971EC947F100B01946 /* SegmentedControlCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298BA0951EC947F100B01946 /* SegmentedControlCell.swift */; };
303303
298BA0981EC947F100B01946 /* SegmentedControlSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298BA0961EC947F100B01946 /* SegmentedControlSectionController.swift */; };
304304
298BA09A1EC947FC00B01946 /* SegmentedControlModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298BA0991EC947FC00B01946 /* SegmentedControlModel.swift */; };
305+
298C7E2821D80BAF00DD2A60 /* Error+GraphQLForbidden.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298C7E2721D80BAF00DD2A60 /* Error+GraphQLForbidden.swift */; };
305306
298C7E2621D7F56600DD2A60 /* SettingsAccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 298C7E2521D7F56600DD2A60 /* SettingsAccountCell.swift */; };
306307
2990B9DB218BF23D009865EB /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2990B9DA218BF23D009865EB /* Router.swift */; };
307308
29921BCC1EF624D400C1E848 /* UIFont+MutableTraits.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29921BCB1EF624D400C1E848 /* UIFont+MutableTraits.swift */; };
@@ -894,6 +895,7 @@
894895
298BA0951EC947F100B01946 /* SegmentedControlCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedControlCell.swift; sourceTree = "<group>"; };
895896
298BA0961EC947F100B01946 /* SegmentedControlSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedControlSectionController.swift; sourceTree = "<group>"; };
896897
298BA0991EC947FC00B01946 /* SegmentedControlModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SegmentedControlModel.swift; sourceTree = "<group>"; };
898+
298C7E2721D80BAF00DD2A60 /* Error+GraphQLForbidden.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Error+GraphQLForbidden.swift"; sourceTree = "<group>"; };
897899
298C7E2521D7F56600DD2A60 /* SettingsAccountCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAccountCell.swift; sourceTree = "<group>"; };
898900
2990B9DA218BF23D009865EB /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
899901
29921BCB1EF624D400C1E848 /* UIFont+MutableTraits.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIFont+MutableTraits.swift"; sourceTree = "<group>"; };
@@ -2285,6 +2287,7 @@
22852287
291E988021975FCB00E5EED9 /* UIApplication+WriteReview.swift */,
22862288
C0E3CD4A21BAE49B00185B57 /* NSRegularExpression+StaticString.swift */,
22872289
C0E3CD4C21BAE65000185B57 /* UIImage+StaticString.swift */,
2290+
298C7E2721D80BAF00DD2A60 /* Error+GraphQLForbidden.swift */,
22882291
);
22892292
path = Utility;
22902293
sourceTree = "<group>";
@@ -2984,6 +2987,7 @@
29842987
296B4E311F7C805600C16887 /* GraphQLIDDecode.swift in Sources */,
29852988
294B11241F7B37D300E04F2D /* ImageCellHeightCache.swift in Sources */,
29862989
294563EC1EE5012100DBCD35 /* Issue+IssueType.swift in Sources */,
2990+
298C7E2821D80BAF00DD2A60 /* Error+GraphQLForbidden.swift in Sources */,
29872991
290CA7642169799600DE04F8 /* AppController.swift in Sources */,
29882992
2955D4A821B46B3D00A393D3 /* InboxFilterRepoSectionController.swift in Sources */,
29892993
2996543C21A76F3A006B2CA9 /* NewFeaturesSectionController.swift in Sources */,

0 commit comments

Comments
 (0)