mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Handle argument exceptions on client side
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Podsync.Helpers;
|
||||
using Podsync.Services.Links;
|
||||
using Podsync.Services.Resolver;
|
||||
using Podsync.Services.Storage;
|
||||
@@ -7,6 +8,7 @@ using Podsync.Services.Storage;
|
||||
namespace Podsync.Controllers
|
||||
{
|
||||
[Route("download")]
|
||||
[HandleException]
|
||||
public class DownloadController : Controller
|
||||
{
|
||||
private readonly IResolverService _resolverService;
|
||||
|
||||
@@ -16,6 +16,7 @@ using Podsync.Services.Storage;
|
||||
namespace Podsync.Controllers
|
||||
{
|
||||
[Route("feed")]
|
||||
[HandleException]
|
||||
public class FeedController : Controller
|
||||
{
|
||||
private const int DefaultPageSize = 50;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace Podsync.Helpers
|
||||
{
|
||||
public class HandleExceptionAttribute : ExceptionFilterAttribute
|
||||
{
|
||||
public override void OnException(ExceptionContext context)
|
||||
{
|
||||
var exception = context.Exception;
|
||||
if (exception is ArgumentNullException || exception is ArgumentException)
|
||||
{
|
||||
context.Result = new BadRequestObjectResult(exception.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
context.Result = new StatusCodeResult((int)HttpStatusCode.InternalServerError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,7 @@ namespace Podsync.Services.Links
|
||||
|
||||
if (string.IsNullOrWhiteSpace(id) || linkType == LinkType.Unknown || provider == Provider.Unknown)
|
||||
{
|
||||
throw new ArgumentException("Failed to parse URL");
|
||||
throw new ArgumentException("This provider is not supported");
|
||||
}
|
||||
|
||||
return new LinkInfo
|
||||
|
||||
@@ -24,12 +24,16 @@ $(function () {
|
||||
error: function (xhr, status, error) {
|
||||
if (xhr.status === 400) {
|
||||
// Bad request
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
|
||||
var text = '';
|
||||
$.each(json, function (key, value) {
|
||||
text += value + '\r\n';
|
||||
});
|
||||
|
||||
try {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
$.each(json, function (key, value) {
|
||||
text += value + '\r\n';
|
||||
});
|
||||
} catch (e) {
|
||||
text = xhr.responseText;
|
||||
}
|
||||
|
||||
err(text);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user