Better error handling for unauthorized list requests.

This commit is contained in:
Steven Hildreth 2019-03-02 08:10:49 -06:00
parent ae292cf90c
commit eee6f88283
9 changed files with 115 additions and 37 deletions

View file

@ -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}")]

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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;
}

View file

@ -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);
}
}
}

View file

@ -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}")]

View file

@ -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);

View file

@ -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);
}
}
}

View file

@ -3,7 +3,7 @@
"Roadie.Api": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5123/"
}