                                     //return inmediatly
                                     success(response)
                                 }
-                            } else if let error = rawResponse.error as NSError? {
-                                var reason = MSError.ResponseFailureReason.badRequest(code: error.code)
-                                
-                                if let statusCode = rawResponse.response?.statusCode
-                                {
-                                    //if the response has a 401 that means we have an authentication issue
-                                    reason = MSError.ResponseFailureReason(code: statusCode)
-                                }
-                                failure(MSError.responseValidationFailed(reason: reason),
-                                        self.errorResponse(fromData: rawResponse.data, request: rawResponse.request))
+                            } else if let (reason, errorDetails) = self.buildError(fromResponse: rawResponse) {
+                                //Figure out if we have an error and an error response
+                                failure(MSError.responseValidationFailed(reason: reason), errorDetails)
                             } else {
                                 //if the request is succesful but has no response (validation for http code has passed also)
                                 success([String:Any]())
                             }
         }
     }
+
     
     //MARK: - Pagination
     

                                    } else {
                                        success(currentResponse)
                                    }
                                } else if let error = rawResponse.error as NSError? {
                                    var reason = MSError.ResponseFailureReason.badRequest(code: error.code)
                                    
                                    if let statusCode = rawResponse.response?.statusCode
                                    {
                                        //if the response has a 401 that means we have an authentication issue
                                        reason = MSError.ResponseFailureReason(code: statusCode)
                                    }

                                    failure(MSError.responseValidationFailed(reason: reason),
                                            self.errorResponse(fromData: rawResponse.data, request: rawResponse.request))
                                }
        }
    }
    
    
    /// Returns an error response from a data stream
    ///

                          method: httpMethod,
                          parameters: parameters,
                          encoding: encoding,
                          headers: headers).validate(statusCode: AlamoNetworkManager.validStatusCodes).responseJSON { rawResponse in
                            //print response in DEBUG mode
                            #if DEBUG
                                debugPrint(rawResponse)
