Improve handling of diff errors

Before we would handle errors by passing them to finish_error on the
uri scheme request. However, it is hard/impossible to obtain error
information on the js side in this way. Now instead we return a
special json document (if the resulting content type is json) and show
an appropriate error message.