Skip to content

Commit

Permalink
API Key console error clarification (#227)
Browse files Browse the repository at this point in the history
* fix: api key console error

* fix: lint space

* fix: error warnings

* Update src/MaplibreGLLayer.js

Co-authored-by: Patrick Arlt <parlt@esri.com>

* fix: error message on v1 response

---------

Co-authored-by: Patrick Arlt <parlt@esri.com>
Co-authored-by: Kizito007 <nwakakelechi49gmail.com>
  • Loading branch information
Kizito007 and patrickarlt authored Jan 2, 2025
1 parent c751baf commit 308156c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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 @@ -67,6 +67,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

0 comments on commit 308156c

Please sign in to comment.