1
0
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:
Maksym Pavlenko
2017-03-06 12:56:16 -08:00
parent 7452b8db75
commit 6eafdc8f49
3 changed files with 24 additions and 7 deletions

View File

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

View File

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

View File

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