                 let failureReason = "Data could not be serialized. Input data was nil."
                 let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason)
                 return .Failure(error)
+            }
+
+            // fail if the data can be converted to an NSError
+            if let dataToError = dataToError {
+                if let dataError = dataToError(data) {
+                    return .Failure(dataError)
+                }
             }
 
             // serialize a `[T]` from the json data

     Adds a handler to be called once the request has finished.

     - parameter queue: The queue to use.
     - parameter path: 0 or more `String` or `Int` that subscript the `JSON`.
     - parameter completionHandler: The code to be executed once the request has finished.
     */
    internal func responseArray<T: JSONDecodable>(
        queue queue: dispatch_queue_t? = nil,
        path: [JSONPathType]? = nil,
        completionHandler: Response<[T], NSError> -> Void)
        -> Self
    {
        return response(
            queue: queue,
            responseSerializer: Request.ArraySerializer(path),
            completionHandler: completionHandler
        )
    }

     Creates a response serializer that returns an object of the given type initialized from
     JSON response data.
     
     - parameter dataToError: A function that interprets an error model to produce an NSError.
     - parameter path: 0 or more `String` or `Int` that subscript the `JSON`.
 
     - returns: An object response serializer.
     */
    internal static func ObjectSerializer<T: JSONDecodable>(
        dataToError: ((NSData -> NSError?)?) = nil,
        path: [JSONPathType]? = nil)
        -> ResponseSerializer<T, NSError>
    {
