Fwrite() expects parameter 2 to be string

This error can occur if you pass a boolean instead of a string to the write method. Example:

$response->getBody()->write(false);

So there seems to be an error somewhere before, but it is not recognizable by the error description and the stack trace. I would check with Xdebug where this error occurs.