Changed error code to 500 instead of 504