Send correct error messages depending on the type of autodiscover method. Microsoft == XML Error Message, JSON == json formatted error message. Sending a generic error 500 is harder to debug in the end.
I guess it should be ErrorCode.
You're right. I've fixed the typo and replaced the msxml errorcode with one that a real exchange server sends outs. Just in case something weird could happing.