Пример #1
0
        public async Task <ActionResult> GetPlanetTwentyTwo(CancellationToken cancellationToken, int planetid)
        {
            // TODO: Implement this controller action
            SinglePlanetViewModel vm = null;

            try
            {
                vm = await _starWarsService.GetPlanetTwentyTwoAsync(planetid, 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));
        }