Commit 600add6e264dedfd44928432cbd1e66a8db01181

Authored by Nathanael Jourdane
1 parent b5d477c6

Display error if resolver or services are not available.

Showing 2 changed files with 18 additions and 17 deletions   Show diff stats
js/app/views/EpnTapUI.js
... ... @@ -67,11 +67,15 @@ Ext.create('Ext.data.Store', {
67 67 type: 'ajax',
68 68 url: 'php/epntap.php',
69 69 extraParams: { action: 'resolver' }
70   - // listeners: {
71   - // exception: function(proxy, response, operation) {
72   - // console.log('Error ', response); //TODO: Use ExtJs alert instead
73   - // }
74   - // }
  70 + },
  71 + errorDisplayed: false,
  72 + listeners: {
  73 + load: function(store, records, successful) {
  74 + if(!successful && !store.errorDisplayed) {
  75 + Ext.Msg.alert('Error', 'Can not load results from the resolver. Please enter target names manually.');
  76 + store.errorDisplayed = true;
  77 + }
  78 + }
75 79 }
76 80 });
77 81  
... ... @@ -121,7 +125,11 @@ Ext.create('Ext.data.Store', {
121 125 {property: 'short_name', direction: 'ASC'}
122 126 ],
123 127 listeners: {
124   - // load: function(record) { console.log(record); }
  128 + load: function(store, records, successful) {
  129 + if(!successful) {
  130 + Ext.Msg.alert('Error', 'Can not get epntap services from registries.');
  131 + }
  132 + }
125 133 }
126 134 });
127 135  
... ...
php/epntap.php
... ... @@ -41,14 +41,8 @@ function resolver() {
41 41 $resolver_url = "http://voparis-registry.obspm.fr/ssodnet/1/autocomplete?q=%22$lastWord%22";
42 42  
43 43 $response = ['success' => true, 'metaData' => ['root' => 'data', 'messageProperty' => 'msg']];
44   - try {
45   - $content = file_get_contents($resolver_url);
46   - } catch (Exception $e) {
47   - error_log('Resolver access error: ' . $e);
48   - $response['success'] = false;
49   - $response['msg'] = "Resolver unreachable on $resolver_url.";
50   - }
51   - try {
  44 + $content = file_get_contents($resolver_url);
  45 + if($content) {
52 46 $result = json_decode($content, true);
53 47 $targets = array();
54 48 foreach($result['hits'] as $e) {
... ... @@ -58,10 +52,9 @@ function resolver() {
58 52 array_push($targets, $target);
59 53 }
60 54 $response['data'] = $targets;
61   - } catch (Exception $e) {
62   - error_log('Resolver type error: ' . $e);
  55 + } else {
63 56 $response['success'] = false;
64   - $response['msg'] = 'The resolver returned a bad result.';
  57 + $response['msg'] = "Resolver unreachable on $resolver_url.";
65 58 }
66 59 return $response;
67 60 }
... ...