mirror of
https://github.com/sphildreth/roadie
synced 2025-02-16 21:18:26 +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
|
@ -56,6 +56,8 @@ namespace Roadie.Api.Controllers
|
|||
[HttpGet]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request, string inc, bool? doRandomize = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await this.ArtistService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
|
@ -67,6 +69,16 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
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}")]
|
||||
[ProducesResponseType(200)]
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -58,6 +59,8 @@ namespace Roadie.Api.Controllers
|
|||
[HttpGet]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await this.BookmarkService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request);
|
||||
|
@ -67,5 +70,15 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
return Ok(result);
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -99,6 +99,8 @@ namespace Roadie.Api.Controllers
|
|||
[HttpGet]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await this.CollectionService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request);
|
||||
|
@ -108,5 +110,15 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
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;
|
||||
|
||||
|
@ -58,6 +59,8 @@ namespace Roadie.Api.Controllers
|
|||
[HttpGet]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request, bool? doRandomize = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await this.GenreService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
|
@ -68,5 +71,15 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
return Ok(result);
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
return StatusCode((int)HttpStatusCode.Unauthorized);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Logger.LogError(ex);
|
||||
}
|
||||
return StatusCode((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,8 @@ namespace Roadie.Api.Controllers
|
|||
[HttpGet]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request, bool? doRandomize = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await this.LabelService.List(roadieUser: await this.CurrentUserModel(),
|
||||
request: request,
|
||||
|
@ -61,6 +63,16 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
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}")]
|
||||
[ProducesResponseType(200)]
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -50,6 +50,8 @@ namespace Roadie.Api.Controllers
|
|||
[HttpGet]
|
||||
[ProducesResponseType(200)]
|
||||
public async Task<IActionResult> List([FromQuery]PagedRequest request, string inc, bool? doRandomize = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await this.TrackService.List(request: request,
|
||||
doRandomize: doRandomize,
|
||||
|
@ -60,5 +62,15 @@ namespace Roadie.Api.Controllers
|
|||
}
|
||||
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…
Add table
Reference in a new issue