Adding 404 to every related query

This commit is contained in:
Zoe Roux 2020-09-24 20:32:55 +02:00
parent 6950b6750a
commit faa908de7b
7 changed files with 56 additions and 128 deletions

View File

@ -45,12 +45,10 @@ namespace Kyoo.Api
new Sort<Show>(sortBy), new Sort<Show>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetCollection(id) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -77,12 +75,10 @@ namespace Kyoo.Api
new Sort<Show>(sortBy), new Sort<Show>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetCollection(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -109,12 +105,10 @@ namespace Kyoo.Api
new Sort<Library>(sortBy), new Sort<Library>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetCollection(id) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -141,12 +135,10 @@ namespace Kyoo.Api
new Sort<Library>(sortBy), new Sort<Library>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetCollection(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});

View File

@ -87,12 +87,10 @@ namespace Kyoo.Api
new Sort<Track>(sortBy), new Sort<Track>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetEpisode(episodeID) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -123,12 +121,10 @@ namespace Kyoo.Api
new Sort<Track>(sortBy), new Sort<Track>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetEpisode(showID, seasonNumber, episodeNumber) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -158,12 +154,10 @@ namespace Kyoo.Api
new Sort<Track>(sortBy), new Sort<Track>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});

View File

@ -49,10 +49,6 @@ namespace Kyoo.Api
return NotFound(); return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -83,10 +79,6 @@ namespace Kyoo.Api
return NotFound(); return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});

View File

@ -56,12 +56,10 @@ namespace Kyoo.Api
new Sort<Show>(sortBy), new Sort<Show>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetLibrary(id) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -88,12 +86,10 @@ namespace Kyoo.Api
new Sort<Show>(sortBy), new Sort<Show>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetLibrary(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -120,12 +116,10 @@ namespace Kyoo.Api
new Sort<Collection>(sortBy), new Sort<Collection>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetLibrary(id) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -152,12 +146,10 @@ namespace Kyoo.Api
new Sort<Collection>(sortBy), new Sort<Collection>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetLibrary(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -184,12 +176,10 @@ namespace Kyoo.Api
new Sort<LibraryItem>(sortBy), new Sort<LibraryItem>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetLibrary(id) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -216,12 +206,10 @@ namespace Kyoo.Api
new Sort<LibraryItem>(sortBy), new Sort<LibraryItem>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetLibrary(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});

View File

@ -45,12 +45,10 @@ namespace Kyoo.Api
new Sort<Episode>(sortBy), new Sort<Episode>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetSeason(seasonID) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -79,12 +77,10 @@ namespace Kyoo.Api
new Sort<Episode>(sortBy), new Sort<Episode>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetSeason(showSlug, seasonNumber) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -112,12 +108,10 @@ namespace Kyoo.Api
new Sort<Episode>(sortBy), new Sort<Episode>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetSeason(showID, seasonNumber) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});

View File

@ -45,12 +45,10 @@ namespace Kyoo.Api
new Sort<Season>(sortBy), new Sort<Season>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(showID) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -77,12 +75,10 @@ namespace Kyoo.Api
new Sort<Season>(sortBy), new Sort<Season>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -109,12 +105,10 @@ namespace Kyoo.Api
new Sort<Episode>(sortBy), new Sort<Episode>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(showID) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -141,12 +135,10 @@ namespace Kyoo.Api
new Sort<Episode>(sortBy), new Sort<Episode>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -172,12 +164,10 @@ namespace Kyoo.Api
new Sort<PeopleRole>(sortBy), new Sort<PeopleRole>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(showID) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -203,12 +193,10 @@ namespace Kyoo.Api
new Sort<PeopleRole>(sortBy), new Sort<PeopleRole>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -235,12 +223,10 @@ namespace Kyoo.Api
new Sort<Genre>(sortBy), new Sort<Genre>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(showID) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -267,12 +253,10 @@ namespace Kyoo.Api
new Sort<Genre>(sortBy), new Sort<Genre>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -327,12 +311,10 @@ namespace Kyoo.Api
new Sort<Library>(sortBy), new Sort<Library>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(showID) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -359,12 +341,10 @@ namespace Kyoo.Api
new Sort<Library>(sortBy), new Sort<Library>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -391,12 +371,10 @@ namespace Kyoo.Api
new Sort<Collection>(sortBy), new Sort<Collection>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(showID) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -423,12 +401,10 @@ namespace Kyoo.Api
new Sort<Collection>(sortBy), new Sort<Collection>(sortBy),
new Pagination(limit, afterID)); new Pagination(limit, afterID));
if (!resources.Any() && await _libraryManager.GetShow(slug) == null)
return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});

View File

@ -49,10 +49,6 @@ namespace Kyoo.Api
return NotFound(); return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});
@ -83,10 +79,6 @@ namespace Kyoo.Api
return NotFound(); return NotFound();
return Page(resources, limit); return Page(resources, limit);
} }
catch (ItemNotFound)
{
return NotFound();
}
catch (ArgumentException ex) catch (ArgumentException ex)
{ {
return BadRequest(new {Error = ex.Message}); return BadRequest(new {Error = ex.Message});