Skip to content

Commit f8317dc

Browse files
authored
Fix: Return an error if the query function is not supported. (#539)
1 parent 3aebae5 commit f8317dc

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/Controller/CustomController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Slim\App;
66
use XHGui\AbstractController;
7+
use XHGui\Exception\NotImplementedException;
78
use XHGui\RequestProxy as Request;
89
use XHGui\Searcher\SearcherInterface;
910

@@ -55,7 +56,12 @@ public function query($query, $retrieve)
5556
}
5657

5758
$perPage = $this->config('page.limit');
59+
try {
60+
$results = $this->searcher->query($conditions, $perPage, $fields);
61+
} catch (NotImplementedException $e) {
62+
return ['error' => ['generic' => 'Not available for your save handler.']];
63+
}
5864

59-
return $this->searcher->query($conditions, $perPage, $fields);
65+
return $results;
6066
}
6167
}

templates/custom/create.twig

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,12 @@
3939
</div><!--/span-->
4040

4141
</div><!--/row-->
42-
<div class="row-fluid">
43-
44-
<div class="span12">
42+
<div class="row-fluid">
43+
<div class="span12" id="run-button-container">
4544
<div class="btn btn-large" style="display: block; margin-left: auto; margin-right: auto; width: 150px;" id="runbutton">Run</div>
4645
<div style="display: block; margin-left: auto; margin-right: auto; width: 150px; display: none" id="loading"><img src="{{ static('img/loading.gif') }}"></div>
4746
</div><!--/span-->
4847

49-
50-
51-
52-
53-
54-
5548
</div><!--/row-->
5649
<table class="table table-hover" id="results">
5750
<thead>
@@ -105,7 +98,6 @@
10598
$("#loading").hide();
10699
if (data.hasOwnProperty('error'))
107100
{
108-
console.log(data.error);
109101
if (data.error.hasOwnProperty('query'))
110102
{
111103
$('#selection').animate(
@@ -127,6 +119,18 @@
127119
}
128120
);
129121
}
122+
123+
if (data.error.hasOwnProperty('generic'))
124+
{
125+
$('#run-button-container').animate(
126+
{ backgroundColor: '#FFD9D9'},
127+
800,
128+
function() {
129+
$(this).animate({ backgroundColor: '#FFF'});
130+
}
131+
);
132+
$('#run-button-container').text(data.error.generic);
133+
}
130134
}else {
131135
$.each( data, function(i, n){
132136
$("#results tbody").append('<tr><td>' + n.meta.url + '</td><td>' + n.meta.SERVER.REQUEST_TIME + '</td><td>' + n.profile['main()'].wt + '</td><td>' + n.profile['main()'].cpu + '</td><td>' + n.profile['main()'].mu + '</td><td>' + n.profile['main()'].pmu + '</td></tr>');

0 commit comments

Comments
 (0)