         var request = URLRequest(url: nsurl, cachePolicy: .useProtocolCachePolicy)
         request.httpMethod = httpMethod
         
-        if let username = self.username, username.isNotEmpty, let password = self.password, password.isNotEmpty {
-            do {
-                let encodedBasicAuth = try convertBasicAuthToBase64(username: username, password: password)
-                request.setValue(encodedBasicAuth, forHTTPHeaderField: "Authorization")
-            } catch MochaError.descriptive(let message) {
-                MochaLogger.log(message)
-            } catch {}
-        }
-        
+        //basic auth
+        let basicAuthResult = createBasicAuth()
+        switch basicAuthResult {
+        case .success(let basicAuth):
+            request.setValue(basicAuth, forHTTPHeaderField: "Authorization")
+        case .failure(let error):
+            MochaLogger.log(error.description)
+        }
+        
+        //headers
         if header.count > 0 {
             for (key, value) in header {
                 request.setValue(value, forHTTPHeaderField: key)

            }
        }
        
        let configuration = URLSessionConfiguration.default
        configuration.timeoutIntervalForRequest = timeout
        
        let session = URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
        
        let dataTask = session.dataTask(with: request, completionHandler: {

    
    // MARK: Conversions
    
    private func createBasicAuth() -> Result<String> {
        guard let username = self.username, username.isNotEmpty else {
            return .failure(.descriptive(message:
                "Username not informed for Basic Authorization"))
        }
        
        guard let password = self.password, password.isNotEmpty else {
            return .failure(.descriptive(message:
                "Password not informed for Basic Authorization"))
        }
        
        let credentials = "\(username):\(password)"
        
        guard let data = credentials.data(using: encoding) else {
            return .failure(.descriptive(message:
                "Error formatting the basic authentication provided."))
        }
        
        let base64Credential = data.base64EncodedString(options: .lineLength64Characters)
        return .success("Basic \(base64Credential)")
    }
    
    private func string(fromDictionary dictionary: [String: Any]) -> String {
