When the body of the response is empty, the functions "xxxResponseSerializer" returns a .Failure.
guard let validData = data where validData.length > 0 else {
let failureReason = "JSON could not be serialized. Input data was nil or zero length."
let error = Error.errorWithCode(.JSONSerializationFailed, failureReason: failureReason)
return .Failure(error)
}
In certain cases (e.g.: 204 responses - no content) a body must not be included. These functions shouldn't return .Failure only when validData is nil and not when his length is 0?
In these cases, you need to use the response serializer instead of the responseXXX serializers. All others throw errors if the data is not valid. This is something that we're continuing to investigate to see if there is a better way to handle it. It's already being tracked in our backlog.
@Ysix please check out #889 if you get a chance. This is our first stab at proper 204 support directly in the response serializers.
Most helpful comment
In these cases, you need to use the
responseserializer instead of theresponseXXXserializers. All others throw errors if the data is not valid. This is something that we're continuing to investigate to see if there is a better way to handle it. It's already being tracked in our backlog.