Automated cherry pick of #4433 (#4483)

* Don't retry nor use response message on 401

* Explicitly call contentHandler on retry exhaustion

* Handle all non 200 responses for id_loaded notifications

Co-authored-by: Miguel Alatzar <this.migbot@gmail.com>
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
Mattermost Build 2020-06-25 21:12:53 +02:00 committed by GitHub
parent e44c4c36d6
commit 3199e25af1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 5 deletions

View file

@ -106,8 +106,27 @@ public class ReceiptDelivery {
Response response = client.newCall(request).execute();
String responseBody = response.body().string();
if (response.code() != 200) {
switch (response.code()) {
case 302:
promise.reject("Receipt delivery failure", "StatusFound");
return;
case 400:
promise.reject("Receipt delivery failure", "StatusBadRequest");
return;
case 401:
promise.reject("Receipt delivery failure", "Unauthorized");
return;
case 500:
promise.reject("Receipt delivery failure", "StatusInternalServerError");
return;
case 501:
promise.reject("Receipt delivery failure", "StatusNotImplemented");
return;
}
throw new Exception(responseBody);
}
JSONObject jsonResponse = new JSONObject(responseBody);
Bundle bundle = new Bundle();
String keys[] = new String[]{"post_id", "category", "message", "team_id", "channel_id", "channel_name", "type", "sender_id", "sender_name", "version"};

View file

@ -15,6 +15,7 @@ class NotificationService: UNNotificationServiceExtension {
func fetchReceipt(notificationId: String, receivedAt: Int, type: String, postId: String, idLoaded: Bool ) -> Void {
if (self.retryIndex >= fibonacciBackoffsInSeconds.count) {
contentHandler(self.bestAttemptContent!)
return
}
@ -23,7 +24,12 @@ class NotificationService: UNNotificationServiceExtension {
receivedAt: receivedAt,
type: type,
postId: postId,
idLoaded: idLoaded) { data, error in
idLoaded: idLoaded) { data, response, error in
if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode != 200 {
contentHandler(self.bestAttemptContent!)
return
}
guard let data = data, error == nil else {
if (idLoaded) {
// Receipt retrieval failed. Kick off retries.

View file

@ -130,10 +130,10 @@ import os.log
}
public func notificationReceipt(notificationId: Any?, receivedAt: Int, type: Any?) {
notificationReceipt(notificationId:notificationId, receivedAt:receivedAt, type:type, postId:nil, idLoaded: false, completion:{_, _ in})
notificationReceipt(notificationId:notificationId, receivedAt:receivedAt, type:type, postId:nil, idLoaded:false, completion:{_, _, _ in})
}
public func notificationReceipt(notificationId: Any?, receivedAt: Int, type: Any?, postId: Any? = nil, idLoaded: Bool, completion: @escaping (Data?, Error?) -> Void) {
public func notificationReceipt(notificationId: Any?, receivedAt: Int, type: Any?, postId: Any? = nil, idLoaded: Bool, completion: @escaping (Data?, URLResponse?, Error?) -> Void) {
if (notificationId != nil) {
let store = StoreManager.shared() as StoreManager
let entities = store.getEntities(true)
@ -162,8 +162,8 @@ import os.log
request.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")
request.httpBody = try? JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
let task = URLSession(configuration: .ephemeral).dataTask(with: request) { data, _, error in
completion(data, error)
let task = URLSession(configuration: .ephemeral).dataTask(with: request) { data, response, error in
completion(data, response, error)
}
task.resume()
}