Raise 404 on incorrect lookup type in URL, not 500. Closes #890.