mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Make error messages more descriptive
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Podsync.Helpers;
|
||||
@@ -45,8 +46,8 @@ namespace Podsync.Controllers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var response = "Could nou resolve URL";
|
||||
if (ex is InvalidOperationException)
|
||||
var response = "Could not resolve URL";
|
||||
if (ex is InvalidOperationException || ex is HttpRequestException)
|
||||
{
|
||||
response = ex.Message;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,19 @@ namespace Podsync.Services.Resolver
|
||||
|
||||
protected override async Task<Uri> ResolveInternal(Uri videoUrl, ResolveFormat format)
|
||||
{
|
||||
var response = await _client.GetStringAsync($"/resolve?url={videoUrl}&quality={format}");
|
||||
return new Uri(response);
|
||||
using(var response = await _client.GetAsync($"/resolve?url={videoUrl}&quality={format}"))
|
||||
{
|
||||
using(response.Content)
|
||||
{
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
throw new HttpRequestException(body);
|
||||
}
|
||||
|
||||
return new Uri(body);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import youtube_dl
|
||||
from youtube_dl.utils import DownloadError
|
||||
from sanic import Sanic
|
||||
from sanic.exceptions import InvalidUsage
|
||||
from sanic.response import text
|
||||
@@ -42,9 +43,13 @@ async def youtube(request):
|
||||
if fmt:
|
||||
opts.update(format=fmt)
|
||||
|
||||
with youtube_dl.YoutubeDL(opts) as ytdl:
|
||||
info = ytdl.extract_info(url, download=False)
|
||||
return text(info['url'])
|
||||
try:
|
||||
with youtube_dl.YoutubeDL(opts) as ytdl:
|
||||
info = ytdl.extract_info(url, download=False)
|
||||
return text(info['url'])
|
||||
except DownloadError as e:
|
||||
msg = str(e)
|
||||
return text(msg, status=511)
|
||||
|
||||
|
||||
def _choose_format(quality, url):
|
||||
|
||||
Reference in New Issue
Block a user