Skip to content

Commit

Permalink
Handle TMDB 503 error response
Browse files Browse the repository at this point in the history
  • Loading branch information
SeinopSys committed Aug 14, 2019
1 parent c467544 commit 85c09dc
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/Controllers/API/AppearancesController.php
Expand Up @@ -180,7 +180,7 @@ function queryPublic() {
Response::fail('ELASTIC_DOWN');
}
if (isset($_GET['size']) && is_numeric($_GET['size']))
$appearances_per_page = CoreUtils::rangeLimit(intval($_GET['size'], 10), 7, 20);
$appearances_per_page = CoreUtils::rangeLimit(\intval($_GET['size'], 10), 7, 20);
else $appearances_per_page = 7;
$pagination = new Pagination('', $appearances_per_page);
$searching = !empty($_GET['q']) && $_GET['q'] !== '';
Expand Down
24 changes: 17 additions & 7 deletions app/Controllers/ShowController.php
Expand Up @@ -2,32 +2,31 @@

namespace App\Controllers;

use ActiveRecord\Cache;
use ActiveRecord\Table;
use App\Auth;
use App\CGUtils;
use App\CoreUtils;
use App\CSRFProtection;
use App\DB;
use App\DeviantArt;
use App\Models\ShowAppearance;
use App\ShowHelper;
use App\HTTP;
use App\Input;
use App\Logs;
use App\Models\Appearance;
use App\Models\Show;
use App\Models\ShowAppearance;
use App\Models\ShowVideo;
use App\Models\ShowVote;
use App\Pagination;
use App\Permission;
use App\Posts;
use App\Regexes;
use App\Response;
use App\ShowHelper;
use App\Time;
use App\TMDBHelper;
use App\Twig;
use App\VideoProvider;
use App\Models\Show;
use App\Models\ShowVideo;
use GuzzleHttp\Exception\ServerException;

class ShowController extends Controller {
public function index(){
Expand Down Expand Up @@ -308,7 +307,7 @@ public function voteApi($params):void {

$table = ShowVote::$table_name;
$vote_count_query = DB::$instance->query(
"SELECT count(*) as value, vote as label FROM $table WHERE show_id = ? GROUP BY vote ORDER BY vote ASC", [$this->show->id]);
"SELECT count(*) as value, vote as label FROM $table WHERE show_id = ? GROUP BY vote ORDER BY vote", [$this->show->id]);
$vote_counts = [];
foreach ($vote_count_query as $row)
$vote_counts[$row['label']] = $row['value'];
Expand Down Expand Up @@ -540,9 +539,20 @@ public function brokenVideos($params):void {
public function synopsis($params) {
$this->load_show($params);

try {
$synopses = $this->show->getSynopses();
}
catch (\Throwable $exception){
$message = $exception->getMessage();
if (strpos($message, '503 Service Temporarily Unavailable') !== false) {
Response::fail('The TMDB API is experiencing a temporary outage, synopsis data is currently unavailable.');
}
}

Response::done([
'html' => Twig::$env->render('show/_synopsis.html.twig', [
'current_episode' => $this->show,
'synopses' => $synopses,
'wrap' => false,
'lazyload' => false,
'signed_in' => Auth::$signed_in,
Expand Down
6 changes: 0 additions & 6 deletions assets/js/pages/colorguide/picker-frame.js
Expand Up @@ -840,12 +840,6 @@
this.updateTabs();
ColorPicker.getInstance().updatePickingState();
}
closeActiveTabConfirm(){
if (!(this._activeTab instanceof Tab))
return;

this._activeTab.getElement().find('.close').trigger('click');
}
}

const $LevelsChangeForm = $.mk('form','levels-changer').append(
Expand Down
9 changes: 7 additions & 2 deletions assets/js/pages/show/view.js
Expand Up @@ -513,9 +513,14 @@
const { id } = el.dataset;

$.API.get(`/show/${id}/synopsis`,$.mkAjaxHandler(function(){
const $section = $(el).closest('section');
const $el = $(el);
const $section = $el.closest('section');
if (!this.status){
$section.remove();
if (this.message)
$el.replaceWith(
$.mk('div').addClass('notice warn').text(this.message)
);
else $section.remove();
return;
}

Expand Down
4 changes: 3 additions & 1 deletion templates/show/_synopsis.html.twig
Expand Up @@ -13,7 +13,9 @@
{% if lazyload is not defined or lazyload == true %}
<div class="synopsis-promise{% if current_episode.twoparter %} twoparter{% endif %}" data-id="{{ current_episode.id }}"></div>
{% else %}
{% set synopses = current_episode.synopses %}
{% if synopses is not defined %}
{% set synopses = current_episode.synopses %}
{% endif %}
{% if synopses is not empty %}
{% for i, synopsis in synopses %}
{% set has_image = synopsis.image is defined and synopsis.image %}
Expand Down

0 comments on commit 85c09dc

Please sign in to comment.