                                                    "Status code: \(response.statusCode ?? -1 ) " +
                                                    "Response: \(errorText)")
                 
-                switch response.statusCode ?? 500 {
-                case 400:
-                    guard errorJson?["error"] == "invalid_grant", let errorDescription = errorJson?["error_description"] else {
-                        fallthrough
-                    }
-                    
-                    tokenResponseDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure(errorDescription))
-                case 403:
-                    guard errorJson?["error_code"] == "FORBIDDEN", let errorDescription = errorJson?["error_description"] else {
-                        fallthrough
-                    }
-                    
-                    tokenResponseDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure(errorDescription))
-                default:
-                    tokenResponseDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure("Failed to retrieve tokens"))
-                }
-            }
-        }
-        
-        let request:Request = Request(url: tokenUrl,method: HttpMethod.POST, headers: headers, queryParameters: nil, timeout: 0)
+                if response.statusCode == 400, errorJson?["error"] == "invalid_grant" {
+                    tokenResponseDelegate.onAuthorizationFailure(error: .authorizationFailure(errorDescription))
+                } else if response.statusCode == 403 {
+                    tokenResponseDelegate.onAuthorizationFailure(error: .authorizationFailure(errorDescription))
+                } else {
+                    tokenResponseDelegate.onAuthorizationFailure(error: .authorizationFailure("Failed to retrieve tokens"))
+                }
+            }
+        }
+        
+        let request = Request(url: tokenUrl,method: HttpMethod.POST, headers: headers, queryParameters: nil, timeout: 0)
         request.timeout = BMSClient.sharedInstance.requestTimeout
         var body = ""
-        var i = 0
-        for (key, val) in bodyParams {
-            body += "\(Utils.urlEncode(key))=\(Utils.urlEncode(val))"
-            if i < bodyParams.count - 1 {
+        for (index, (key: key, value: value)) in bodyParams.enumerated() {
+            body += "\(Utils.urlEncode(key))=\(Utils.urlEncode(value))"
+            if index < bodyParams.count - 1 {
                 body += "&"
             }
-            i += 1
         }
         sendRequest(request: request, body: body.data(using: .utf8), internalCallBack: internalCallback)
 

            
            guard let accessTokenString = (responseJson["access_token"] as? String), let idTokenString = (responseJson["id_token"] as? String) else {
                TokenManager.logger.error(message: "Failed to parse server response - no access or identity token")
                tokenResponseDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure("Failed to parse server response - no access or identity token"))
                return
            }
            guard let accessToken = AccessTokenImpl(with: accessTokenString), let identityToken:IdentityTokenImpl = IdentityTokenImpl(with: idTokenString) else {
                TokenManager.logger.error(message: "Failed to parse tokens")
                tokenResponseDelegate.onAuthorizationFailure(error: AuthorizationError.authorizationFailure("Failed to parse tokens"))
                return
            }
            let refreshTokenString = responseJson["refresh_token"] as? String

                                                         response:response)
        } catch (_) {
            TokenManager.logger.error(message: "Failed to parse server response - failed to parse json")
            tokenResponseDelegate.onAuthorizationFailure(error: .authorizationFailure("Failed to parse server response - failed to parse json"))
            return
        }
        
