Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Key console error clarification #227

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/MaplibreGLLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ export var MaplibreGLJSLayer = Layer.extend({

this._glMap = new maplibregl.Map(options);

// Listen for style data error (401 Unauthorized)
this._glMap.on('error', function (error) {
if (error.error && error.error.status === 401) {
console.warn('Invalid or expired API key. Please check that API key is not expired and has the basemaps privilege assigned.');
}
});

// Fire event for Maplibre "styledata" event.
this._glMap.once(
'styledata',
Expand Down
15 changes: 15 additions & 0 deletions src/VectorBasemapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ export var VectorBasemapLayer = VectorTileLayer.extend({
} else {
styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey);
}
// show error warning on successful response for previous version(1)
if (this.options.version && this.options.version === 1) {
fetch(styleUrl)
.then(response => {
return response.json();
})
.then(styleData => {
if (styleData.error) {
console.warn('Error:', styleData.error.message);
}
})
.catch(error => {
console.warn('Error:', error.message);
});
}
this._createMaplibreLayer(styleUrl);
},

Expand Down
Loading