mirror of
https://github.com/sphildreth/roadie
synced 2024-11-22 04:03:10 +00:00
Better error handling for unauthorized list requests.
This commit is contained in:
parent
ae292cf90c
commit
eee6f88283
9 changed files with 115 additions and 37 deletions
|
@ -57,15 +57,27 @@ namespace Roadie.Api.Controllers
|
|||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request, string inc, bool? doRandomize = false)
|
||||
{
|
||||
var result = await this.ArtistService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
doRandomize: doRandomize ?? false,
|
||||
onlyIncludeWithReleases: false);
|
||||
if (!result.IsSuccess)
|
||||
try
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
var result = await this.ArtistService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
doRandomize: doRandomize ?? false,
|
||||
onlyIncludeWithReleases: false);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
return Ok(result);
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
|
||||
[HttpPost("mergeArtists/{artistToMergeId}/{artistToMergeIntoId}")]
|
||||
|
|
|
@ -7,6 +7,7 @@ using Roadie.Api.Services;
|
|||
using Roadie.Library.Caching;
|
||||
using Roadie.Library.Identity;
|
||||
using Roadie.Library.Models.Pagination;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -59,13 +60,25 @@ namespace Roadie.Api.Controllers
|
|||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request)
|
||||
{
|
||||
var result = await this.BookmarkService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request);
|
||||
if (!result.IsSuccess)
|
||||
try
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
var result = await this.BookmarkService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
return Ok(result);
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -100,13 +100,25 @@ namespace Roadie.Api.Controllers
|
|||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request)
|
||||
{
|
||||
var result = await this.CollectionService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request);
|
||||
if (!result.IsSuccess)
|
||||
try
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
var result = await this.CollectionService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
return Ok(result);
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -55,7 +55,7 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
if(this._currentUser == null)
|
||||
{
|
||||
throw new Exception("Access Denied");
|
||||
throw new UnauthorizedAccessException("Access Denied");
|
||||
}
|
||||
return this._currentUser;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ using Roadie.Api.Services;
|
|||
using Roadie.Library.Caching;
|
||||
using Roadie.Library.Identity;
|
||||
using Roadie.Library.Models.Pagination;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -59,14 +60,26 @@ namespace Roadie.Api.Controllers
|
|||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request, bool? doRandomize = false)
|
||||
{
|
||||
var result = await this.GenreService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
doRandomize: doRandomize);
|
||||
if (!result.IsSuccess)
|
||||
try
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
var result = await this.GenreService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
doRandomize: doRandomize);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
return Ok(result);
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,14 +52,26 @@ namespace Roadie.Api.Controllers
|
|||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request, bool? doRandomize = false)
|
||||
{
|
||||
var result = await this.LabelService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
doRandomize: doRandomize);
|
||||
if (!result.IsSuccess)
|
||||
try
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
var result = await this.LabelService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
doRandomize: doRandomize);
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
return Ok(result);
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
|
||||
[HttpPost("uploadImage/{id}")]
|
||||
|
|
|
@ -106,6 +106,10 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
return Ok(result);
|
||||
}
|
||||
catch(UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
|
|
|
@ -51,14 +51,26 @@ namespace Roadie.Api.Controllers
|
|||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request, string inc, bool? doRandomize = false)
|
||||
{
|
||||
var result = await this.TrackService.List(request: request,
|
||||
doRandomize: doRandomize,
|
||||
roadieUser: await this.CurrentUserModel());
|
||||
if (!result.IsSuccess)
|
||||
try
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
var result = await this.TrackService.List(request: request,
|
||||
doRandomize: doRandomize,
|
||||
roadieUser: await this.CurrentUserModel());
|
||||
if (!result.IsSuccess)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
return Ok(result);
|
||||
}
|
||||
return Ok(result);
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
"Roadie.Api": {
|
||||
"commandName": "Project",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Production"
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:5123/"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue