--- /dev/null
+<script>
+ import { error_store } from '../lib/stores.js';
+
+ let error_message;
+
+ error_store.subscribe(text => { error_message = text; });
+
+ function dismiss_message() {
+ error_store.set(null);
+ }
+</script>
+
+{#if error_message}
+ <div id="error" class="container-fluid alert-danger py-3 px-4">
+ {error_message}
+
+ <button type="button" class="close" aria-label="dismiss" on:click={dismiss_message}>
+ <span aria-hidden="true">×</span>
+ </button>
+ </div>
+{/if}
import PageLink from './PageLink.svelte';
import ReverseLink from './ReverseLink.svelte';
import LastUpdated from './LastUpdated.svelte';
+ import Error from './Error.svelte';
import { page } from '../lib/stores.js';
import { get_config_value } from '../lib/config_reader.js';
<section class="search-section">
<slot/>
</section>
+<Error/>
<LastUpdated/>
import { get_config_value } from './config_reader.js';
-import { last_api_request_url_store } from './stores.js';
+import { last_api_request_url_store, error_store } from './stores.js';
function api_request_progress(status) {
var api_url = generate_nominatim_api_url(endpoint_name, params);
api_request_progress('start');
+ if (endpoint_name !== 'status') last_api_request_url_store.set(null);
- await fetch(api_url)
- .then(response => response.json())
- .then(data => {
- callback(data);
- api_request_progress('finish');
- });
+ try {
+ await fetch(api_url)
+ .then(response => response.json())
+ .then(data => {
+ if (data.error) {
+ error_store.set(data.error.message);
+ }
+ callback(data);
+ api_request_progress('finish');
+ });
+ } catch (error) {
+ error_store.set(`Error fetching data from ${api_url} (${error})`);
+ api_request_progress('finish');
+ }
if (endpoint_name !== 'status') last_api_request_url_store.set(api_url);
}
export const map_store = writable();
export const results_store = writable();
export const last_api_request_url_store = writable();
+export const error_store = writable();
export const page = writable();
/**
}
page.set({ tab: pagename, params: params });
+ last_api_request_url_store.set(null);
+ error_store.set(null);
}
import Map from '../components/Map.svelte';
let aPlace;
- let errorResponse;
let base_url = window.location.search;
- let current_result;
let api_request_params;
+ let api_request_finished = false;
function loaddata(search_params) {
api_request_params = {
polygon_geojson: 1,
format: 'json'
};
+ api_request_finished = false;
if (api_request_params.place_id || (api_request_params.osmtype && api_request_params.osmid)) {
fetch_from_api('details', api_request_params, function (data) {
window.scrollTo(0, 0);
- if (data.error) {
- errorResponse = data;
- current_result = undefined;
- } else {
- aPlace = data;
- errorResponse = undefined;
- current_result = data;
- }
+ api_request_finished = true;
+ aPlace = (data && !data.error) ? data : undefined;
});
} else {
aPlace = undefined;
<Header>
<SearchSectionDetails api_request_params={api_request_params}/>
</Header>
-{#if errorResponse}
- {errorResponse.error.message}
-{/if}
-{#if aPlace}
- <div class="container">
+
+<div class="container">
+ {#if aPlace}
<div class="row">
<div class="col-sm-10">
<h1>
</div>
<div class="col-md-6">
<div id="map-wrapper">
- <Map {current_result} />
+ <Map current_result={aPlace} />
</div>
</div>
</div>
</table>
</div>
</div>
- </div>
-{:else if (window.location.search === '')}
- <!-- <DetailsIndex/> -->
-{:else}
- No such place found.
-{/if}
+ {:else if (window.location.search !== '' && api_request_finished)}
+ No such place found.
+ {/if}
+</div>