🥅 added error handling for get-endpoint

Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
haraldnilsen 2023-09-19 10:14:35 +02:00
parent c662c48e59
commit f2d00947c8

View file

@ -16,9 +16,30 @@ public class MovieController: ControllerBase
_context = context;
}
[HttpGet(Name = "GetMovie")]
public IEnumerable<MovieDB> Get()
[HttpGet(Name = "GetMovies")]
public ActionResult<IEnumerable<MovieDB>> Get([FromQuery]int pageNumber = 1, [FromQuery] int pageSize = 5)
{
return _context.Movies.ToList();
try
{
var movies = _context.Movies.ToList();
return Ok(movies);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error fetching movies");
return StatusCode(500, "Internal server error");
}
}
// [HttpPost(Name = "PostMovie")]
// public ActionResult<> Post([FromQuery] string movieTitle) {
// try
// {
// }
// catch (Exception ex)
// {
// }
// }
}