added more specific errors and encoded the url so that it doesn't throw a 500 error