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

Conversation

Kizito007
Copy link
Contributor

Improved console error message for invalid API Key

image
#158

Cc @gavinr-maps

@gavinr-maps
Copy link
Contributor

gavinr-maps commented Oct 23, 2024

@Kizito007 thank you for the PR!

I am not seeing the warning in my testing when I would expect to see it. Here's what I'm doing:

  1. Cloning the repo with your modified branch
  2. npm install
  3. npm run build
  4. npm start
  5. In the browser window that opens, click the links for "examples" > "quickstart-dev.html"
    • Expected: Warning "Invalid API Key ...."
    • Actual: No warning: image

@Kizito007
Copy link
Contributor Author

Hey @gavinr-maps

You're right on track. However, the error is expected to warn for "example" HTML files that include apiKey in their script such as:

languages.html, worldview.html etc.

Once you click on a location and the API key is not there or invalid it throws a warning to the console

@hhkaos
Copy link
Member

hhkaos commented Oct 24, 2024

UPDATE: sorry I mistakenly tried the wrong branch. Now updated

You are right @Kizito007, but I agree with @gavinr-maps , the warning is not showing as expected on start on every situation.

Quickstart dev

http://127.0.0.1:8765/examples/quickstart-dev.html

Screenshot 2024-10-24 at 15 10 37

Worldview

http://127.0.0.1:8765/examples/worldview.html

On start (which is OK because the sample is created to not load a map until you select a country):
Screenshot 2024-10-24 at 15 12 37

After selecting a country
Screenshot 2024-10-24 at 15 12 54

Languages

http://127.0.0.1:8765/examples/languages.html

Screenshot 2024-10-24 at 15 11 42

@Kizito007
Copy link
Contributor Author

Hey @hhkaos

Thanks for trying it out. What additional improvements will you suggest we work on for this issue?

@hhkaos
Copy link
Member

hhkaos commented Oct 29, 2024

Sorry for the delayed response @Kizito007. You should check the HTTP response, sometimes you can get a 200 with an error message:
2024-10-29_12-18-43

Thanks!

@Kizito007
Copy link
Contributor Author

Kizito007 commented Oct 29, 2024

It's all good @hhkaos

I just pushed an update which shows the API error message as a warning on the console.

Kindly check it out

image

Copy link
Member

@hhkaos hhkaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would like to avoid an additional fetch request if possible

@@ -65,6 +65,19 @@ export var VectorBasemapLayer = VectorTileLayer.extend({
} else {
styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey);
}
// show error warning on successful response
fetch(styleUrl)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid sending an additional fetch request??

I have been checking the previous error message:
Screenshot 2024-10-30 at 08 35 38

But it doesn't give us the information we need from the REST API, right? I have been checking other events unsuccessfully.

The style.ts is part of MapLibre library so we can not access to any.

// cc: @gavinr-maps @gowin20 any clue on how we can get that REST response?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kizito007 I discussed this today with @gavinr-maps and @hhkaos. We are ok with the additional fetch request but only if the options.version is 1 since auth errors with the version 2 service will get covered by the error event above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm @patrickarlt are there any variations from version 1 such as 1.1.0 or 1.0.1 so I can safely check if options.version === 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, version is only 1 or 2 - see here:

if (key.includes('/')) options.version = 2;
else options.version = 1;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback bosses @gavinr-maps @hhkaos @patrickarlt

I just pushed the update.

@hhkaos
Copy link
Member

hhkaos commented Nov 2, 2024

I was talking to the team, and we think the correct approach would be to listen to the
error event here: https://github.com/Esri/esri-leaflet-vector/blob/master/src/VectorTileLayer.js#L113-L119

Your code in the PR should work https://github.com/Esri/esri-leaflet-vector/pull/227/files#diff-3f514e068697c8df07638716f1c0ebe08329ee0b5e15d993d4d89fb2c004d4b4R171-R177
if that doesn't give us to info back from the REST API, then we probably need other major changes, like manually requesting the style so we can handle the error ourselves

If we don't get the exact error messages we want back, we could say something like "Request for style failed. This is commonly caused by an incorrectly configured, expired, or invalid API key or an expired access token"

I hope this helps! 🙏

@Kizito007
Copy link
Contributor Author

Thank you for the reach out @hhkaos and my apologies for the late response. My windows ran into some issues but it's all good now.

I'll look into it and respond with my feedback 🫡

@Kizito007
Copy link
Contributor Author

Hey @hhkaos

I've been trying to listen for error events in the VectorTileLayer and VectorBaseMapLayer but it doesn't seem to return the error on the error event

Code:

{60F9390A-6D0A-42A4-8EAD-254862DC11F1}

Console (quickstart-dev.html):

{87A946FE-D627-4AFD-915E-26BE545899D7}

@hhkaos
Copy link
Member

hhkaos commented Nov 20, 2024

I think you are right. When using some basemaps endpoints that return HTTP status 200 with an error encoded as a JSON object, there is no way to get that JSON and parse it because Maplibre does not trigger any errors.

I just tried using quickstart-dev.html with:

  • L.esri.Vector.vectorBasemapLayer("ArcGIS:Streets", ...
  • VS using L.esri.Vector.vectorBasemapLayer("arcgis/navigation", .....

Here you can see the result
2024-11-20_11-38-39
2024-11-20_11-40-27

So I would say maybe we can add a small logic before the fetch you added, just to make sure that that fetch request is only sent when using the V1 enumerations or Custom basemap styles.

What do you think? // cc: @gavinr-maps @patrickarlt

@Kizito007
Copy link
Contributor Author

@hhkaos should I proceed to add a logic before the fetch?

@hhkaos
Copy link
Member

hhkaos commented Nov 27, 2024

Hi Kizito!, I'm trying to confirm internally with the team, but now it is Thanksgiving in the US, and I think it might take until next week for me to be able to confirm,

@Kizito007
Copy link
Contributor Author

Thanks for the feedback 😁 and Happy Thanksgiving to everyone!

Copy link
Contributor

@patrickarlt patrickarlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kizito007 we met as a group and discussed this today. I left some feedback for you. Le t me know if this makes sense.

src/MaplibreGLLayer.js Outdated Show resolved Hide resolved
@@ -65,6 +65,19 @@ export var VectorBasemapLayer = VectorTileLayer.extend({
} else {
styleUrl = getBasemapStyleUrl(this.options.key, this.options.apikey);
}
// show error warning on successful response
fetch(styleUrl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kizito007 I discussed this today with @gavinr-maps and @hhkaos. We are ok with the additional fetch request but only if the options.version is 1 since auth errors with the version 2 service will get covered by the error event above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants