Skip to content

Commit

Permalink
[CastIt.Application] Added some new exceptions
Browse files Browse the repository at this point in the history
Removed not needed code
  • Loading branch information
Wolfteam committed Jul 4, 2021
1 parent 4625ddc commit 7bfcf0e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 102 deletions.
28 changes: 0 additions & 28 deletions CastIt.Application/Common/Delegates.cs

This file was deleted.

51 changes: 0 additions & 51 deletions CastIt.Application/Interfaces/IBaseWebServer.cs

This file was deleted.

20 changes: 0 additions & 20 deletions CastIt.Application/Server/WebServerDelegates.cs

This file was deleted.

10 changes: 7 additions & 3 deletions CastIt.Application/Youtube/YoutubeUrlDecoder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CastIt.Application.Common.Extensions;
using CastIt.Application.Interfaces;
using CastIt.Domain.Exceptions;
using CastIt.Domain.Models.Youtube;
using HtmlAgilityPack;
using Microsoft.Extensions.Logging;
Expand Down Expand Up @@ -75,7 +76,10 @@ public async Task<YoutubeMedia> Parse(
using var httpClient = new HttpClient();
var response = await httpClient.GetAsync(url).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
throw new Exception($"Couldn't retrieve youtube video. StatusCode = {response.StatusCode}");
{
_logger.LogWarning($"Couldn't retrieve youtube video. StatusCode = {response.StatusCode}");
throw new UrlCouldNotBeParsedException(url);
}

var body = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
body = body.Replace("\\/", "/");
Expand All @@ -95,7 +99,7 @@ public async Task<YoutubeMedia> Parse(
if (!qualities.Any())
{
_logger.LogWarning($"{nameof(Parse)}: Couldn't retrieve any qualities for video = {url} in body = {body}");
throw new InvalidOperationException($"Couldn't retrieve any qualities for video = {url}");
throw new UrlCouldNotBeParsedException(url);
}
media.Qualities.AddRange(qualities.Select(q => q.Key));
int closest = qualities
Expand All @@ -116,7 +120,7 @@ public async Task<YoutubeMedia> Parse(
if (string.IsNullOrEmpty(media.Url))
{
_logger.LogInformation($"{nameof(Parse)}: Url couldn't be parsed");
throw new Exception($"Url couldn't be parsed for url = {url}");
throw new UrlCouldNotBeParsedException(url);
}

_logger.LogInformation($"{nameof(Parse)}: Url was completely parsed. Media = {JsonConvert.SerializeObject(media)}");
Expand Down
12 changes: 12 additions & 0 deletions CastIt.Domain/Exceptions/FileNotReadyException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CastIt.Domain.Enums;

namespace CastIt.Domain.Exceptions
{
public class FileNotReadyException : BaseAppException
{
public FileNotReadyException(string message, AppMessageType errorMessageId = AppMessageType.OneOrMoreFilesAreNotReadyYet)
: base(message, errorMessageId)
{
}
}
}
12 changes: 12 additions & 0 deletions CastIt.Domain/Exceptions/UrlCouldNotBeParsedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using CastIt.Domain.Enums;

namespace CastIt.Domain.Exceptions
{
public class UrlCouldNotBeParsedException : BaseAppException
{
public UrlCouldNotBeParsedException(string url, AppMessageType errorMessageId = AppMessageType.UrlCouldntBeParsed)
: base($"The {url} could not be parsed", errorMessageId)
{
}
}
}

0 comments on commit 7bfcf0e

Please sign in to comment.