Nicer error display

This commit is contained in:
Pablo Ferreiro 2022-09-03 14:01:03 +02:00
parent 96fb2fd428
commit 38557fafa6
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
15 changed files with 53 additions and 32 deletions

View file

@ -38,7 +38,6 @@ Apply to: Main window (address bar)
* Fix embed styling * Fix embed styling
* Fix crash when invalid vm.tiktok.com/CODE or www.tiktok.com/t/CODE is provided * Fix crash when invalid vm.tiktok.com/CODE or www.tiktok.com/t/CODE is provided
* Add custom amount of videos per page * Add custom amount of videos per page
* Discover does not work
## Credits ## Credits
[@TheFrenchGhosty](https://github.com/TheFrenchGhosty): Initial Dockerfile and fixes to a usable state. You can check his Docker image [here](https://github.com/PussTheCat-org/docker-proxitok-quay) on Github or [here](https://quay.io/repository/pussthecatorg/proxitok) on Quay [@TheFrenchGhosty](https://github.com/TheFrenchGhosty): Initial Dockerfile and fixes to a usable state. You can check his Docker image [here](https://github.com/PussTheCat-org/docker-proxitok-quay) on Github or [here](https://quay.io/repository/pussthecatorg/proxitok) on Quay

View file

@ -14,7 +14,7 @@ class DiscoverController {
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('discover'), new FeedTemplate('Discover', $feed)); $latte->render(Misc::getView('discover'), new FeedTemplate('Discover', $feed));
} else { } else {
ErrorHandler::show($feed->meta); ErrorHandler::showMeta($feed->meta);
} }
} }
} }

View file

@ -9,12 +9,14 @@ use App\Models\VideoTemplate;
class EmbedController { class EmbedController {
static public function v2(int $id) { static public function v2(int $id) {
$api = Wrappers::api(); $api = Wrappers::api();
$feed = $api->getVideoByID($id); $video = $api->video($id);
if ($feed->meta->success) { $video->feed();
if ($video->ok()) {
$data = $video->getFull();
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('video'), new VideoTemplate($feed->items[0], $feed->info->detail, true)); $latte->render(Misc::getView('video'), new VideoTemplate($data->feed->items[0], $data->info->detail, true));
} else { } else {
ErrorHandler::show($feed->meta); ErrorHandler::showMeta($video->error());
} }
} }
} }

View file

@ -18,7 +18,7 @@ class MusicController {
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('music'), new FullTemplate('Music', $data)); $latte->render(Misc::getView('music'), new FullTemplate('Music', $data));
} else { } else {
ErrorHandler::show($music->error()); ErrorHandler::showMeta($music->error());
} }
} }
} }

View file

@ -15,7 +15,7 @@ class RedirectController {
case 'url': case 'url':
$endpoint = self::to_endpoint($term); $endpoint = self::to_endpoint($term);
if (!$endpoint) { if (!$endpoint) {
echo 'Invalid or unknown TikTok URL format'; ErrorHandler::showText(400, 'Invalid TikTok URL');
return; return;
} }
break; break;

View file

@ -18,7 +18,7 @@ class TagController {
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('tag'), new FullTemplate('Tag', $data)); $latte->render(Misc::getView('tag'), new FullTemplate('Tag', $data));
} else { } else {
ErrorHandler::show($hashtag->error()); ErrorHandler::showMeta($hashtag->error());
} }
} }

View file

@ -20,7 +20,7 @@ class TrendingController {
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('trending'), new FeedTemplate('Trending', $feed)); $latte->render(Misc::getView('trending'), new FeedTemplate('Trending', $feed));
} else { } else {
ErrorHandler::show($trending->error()); ErrorHandler::showMeta($trending->error());
} }
} }

View file

@ -17,14 +17,13 @@ class UserController {
if ($user->ok()) { if ($user->ok()) {
$data = $user->getFull(); $data = $user->getFull();
if ($data->info->detail->privateAccount) { if ($data->info->detail->privateAccount) {
http_response_code(403); ErrorHandler::showText(401, "Private account detected! Not supported");
echo 'Private account detected! Not supported'; return;
exit;
} }
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('user'), new FullTemplate($data->info->detail->nickname, $data)); $latte->render(Misc::getView('user'), new FullTemplate($data->info->detail->nickname, $data));
} else { } else {
ErrorHandler::show($user->error()); ErrorHandler::showMeta($user->error());
} }
} }
@ -37,7 +36,7 @@ class UserController {
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('video'), new VideoTemplate($data->feed->items[0], $data->info->detail)); $latte->render(Misc::getView('video'), new VideoTemplate($data->feed->items[0], $data->info->detail));
} else { } else {
ErrorHandler::show($video->error()); ErrorHandler::showMeta($video->error());
} }
} }

View file

@ -5,9 +5,15 @@ use App\Models\ErrorTemplate;
use TikScraper\Models\Meta; use TikScraper\Models\Meta;
class ErrorHandler { class ErrorHandler {
static public function show(Meta $meta) { static public function showMeta(Meta $meta) {
http_response_code($meta->http_code); http_response_code($meta->http_code);
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('error'), new ErrorTemplate($meta)); $latte->render(Misc::getView('error'), new ErrorTemplate($meta->http_code, $meta->tiktok_msg, $meta->tiktok_code));
}
static public function showText(int $code, string $msg) {
http_response_code($code);
$latte = Wrappers::latte();
$latte->render(Misc::getView('error'), new ErrorTemplate($code, $msg));
} }
} }

View file

@ -1,13 +1,16 @@
<?php <?php
namespace App\Models; namespace App\Models;
use TikScraper\Models\Meta;
class ErrorTemplate extends BaseTemplate { class ErrorTemplate extends BaseTemplate {
public Meta $error; public int $http_code = 502;
public ?int $tiktok_code = -1;
public string $msg = '';
function __construct(object $error) {
function __construct(int $http_code, string $msg, ?int $tiktok_code = null) {
parent::__construct('Error'); parent::__construct('Error');
$this->error = $error; $this->http_code = $http_code;
$this->msg = $msg;
$this->tiktok_code = $tiktok_code;
} }
} }

View file

@ -1,5 +1,6 @@
<nav class="navbar" role="navigation" aria-label="main navigation"> <nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand"> <div class="navbar-brand">
<a href="{path('/')}" class="navbar-item">ProxiTok</a>
<a role="button" id="navbar-burger" class="navbar-burger" aria-label="menu" aria-expanded="false"> <a role="button" id="navbar-burger" class="navbar-burger" aria-label="menu" aria-expanded="false">
<span aria-hidden="true"></span> <span aria-hidden="true"></span>
<span aria-hidden="true"></span> <span aria-hidden="true"></span>
@ -9,9 +10,6 @@
<div id="navbar-menu" class="navbar-menu"> <div id="navbar-menu" class="navbar-menu">
<div class="navbar-start"> <div class="navbar-start">
<a href="{path('/')}" class="navbar-item">
{include './icon.latte', icon: 'home', text: 'Home'}
</a>
<a href="{path('/settings')}" class="navbar-item">Settings</a> <a href="{path('/settings')}" class="navbar-item">Settings</a>
<a href="{path('/about')}" class="navbar-item"> <a href="{path('/about')}" class="navbar-item">
{include './icon.latte', icon: 'info', text: 'About'} {include './icon.latte', icon: 'info', text: 'About'}

View file

@ -1,7 +1,7 @@
{ {
"name": "pablouser1/proxitok", "name": "pablouser1/proxitok",
"description": "An alternative frontend for TikTok", "description": "An alternative frontend for TikTok",
"version": "2.4.1.0", "version": "2.4.2.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"type": "project", "type": "project",
"authors": [ "authors": [

2
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "a7e4990ac4c1935a8cdc93939bf26dc9", "content-hash": "ec01a866b0314de1e8345a625b066075",
"packages": [ "packages": [
{ {
"name": "bramus/router", "name": "bramus/router",

View file

@ -1,9 +1,15 @@
<?php <?php
/** @var \Bramus\Router\Router $router */ /** @var \Bramus\Router\Router $router */
use App\Helpers\ErrorHandler;
use App\Helpers\Misc; use App\Helpers\Misc;
use App\Helpers\Wrappers; use App\Helpers\Wrappers;
use App\Models\BaseTemplate; use App\Models\BaseTemplate;
$router->set404(function () {
ErrorHandler::showText(404, "That endpoint doesn't exist");
});
$router->get('/', function () { $router->get('/', function () {
$latte = Wrappers::latte(); $latte = Wrappers::latte();
$latte->render(Misc::getView('home'), new BaseTemplate('Home')); $latte->render(Misc::getView('home'), new BaseTemplate('Home'));

View file

@ -2,9 +2,17 @@
{block content} {block content}
<p class="title">There was an error processing your request!</p> <p class="title">There was an error processing your request!</p>
<p class="subtitle">HTTP Code: {$error->http_code}</p> <div class="content">
<p class="subtitle">API error code {$error->tiktok_code} ({$error->tiktok_msg})</p> <p>HTTP Code: {$http_code}</p>
{if $error->tiktok_code === 10000 || $error->tiktok_code === -1} {if isset($tiktok_code)}
<a href="{path('/verify')}">What does this mean?</a> <p>
{/if} <span>API error code {$tiktok_code} ({$msg})</span>
{if $tiktok_code === 10000 || $tiktok_code === -1}
<a href="{path('/verify')}">What does this mean?</a>
{/if}
</p>
{else}
<p>{$msg}</p>
{/if}
</div>
{/block} {/block}