Esempio n. 1
0
        public async Task <ActionResult> GetAllPlanets(CancellationToken cancellationToken)
        {
            // TODO: Implement this controller action
            AllPlanetsViewModel vm = null;

            try
            {
                vm = await _starWarsService.GetAllPlanetsAsync(cancellationToken);
            }
            catch (NullReferenceException ex)
            {
                if (ex.Message.Contains("not found"))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                }

                //potentially log error here and return 500
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
            catch (Exception ex)
            {
                //potentially log error and rethrow error, or, in this case, just return 500
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }

            return(View(vm));
        }