Returning errors in json format