Spaces:
Sleeping
Sleeping
Joffrey Thomas commited on
Commit ·
1fd2418
1
Parent(s): 2daed3f
Explain Google Maps key errors instead of Google's generic error tile
Browse files- static/app.js +11 -1
static/app.js
CHANGED
|
@@ -55,11 +55,21 @@ function avatarOf(key, size = "") {
|
|
| 55 |
|
| 56 |
/* ================= Google Maps ================= */
|
| 57 |
let mapsReady = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
function loadMaps(key) {
|
|
|
|
| 59 |
mapsReady ??= new Promise((resolve, reject) => {
|
| 60 |
window.__gmInit = resolve;
|
| 61 |
const s = document.createElement("script");
|
| 62 |
-
s.src = `https://maps.googleapis.com/maps/api/js?key=${encodeURIComponent(key)}&v=weekly&callback=__gmInit`;
|
| 63 |
s.async = true;
|
| 64 |
s.onerror = () => reject(new Error("Google Maps failed to load"));
|
| 65 |
document.head.appendChild(s);
|
|
|
|
| 55 |
|
| 56 |
/* ================= Google Maps ================= */
|
| 57 |
let mapsReady = null;
|
| 58 |
+
function mapsFailed(msg) {
|
| 59 |
+
console.error(msg);
|
| 60 |
+
$("#lobby-error").textContent = msg;
|
| 61 |
+
if (!$("#lobby").classList.contains("active")) alert(msg);
|
| 62 |
+
}
|
| 63 |
+
// Google calls this when it rejects the key, e.g. RefererNotAllowedMapError.
|
| 64 |
+
window.gm_authFailure = () => mapsFailed(
|
| 65 |
+
`Google Maps rejected the browser key for this site. Add ${location.origin}/* to the key's allowed websites in Google Cloud Console.`);
|
| 66 |
+
|
| 67 |
function loadMaps(key) {
|
| 68 |
+
if (!key) return Promise.reject(new Error("Google Maps key missing: set the GOOGLE_MAPS_BROWSER_KEY secret."));
|
| 69 |
mapsReady ??= new Promise((resolve, reject) => {
|
| 70 |
window.__gmInit = resolve;
|
| 71 |
const s = document.createElement("script");
|
| 72 |
+
s.src = `https://maps.googleapis.com/maps/api/js?key=${encodeURIComponent(key)}&v=weekly&loading=async&callback=__gmInit`;
|
| 73 |
s.async = true;
|
| 74 |
s.onerror = () => reject(new Error("Google Maps failed to load"));
|
| 75 |
document.head.appendChild(s);
|