🥅 added error handling for get-endpoint
Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
parent
c662c48e59
commit
f2d00947c8
1 changed files with 24 additions and 3 deletions
|
@ -16,9 +16,30 @@ public class MovieController: ControllerBase
|
||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet(Name = "GetMovie")]
|
[HttpGet(Name = "GetMovies")]
|
||||||
public IEnumerable<MovieDB> Get()
|
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)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
Reference in a new issue