Error documents can be set as well
Handle null
Updated example for errors