Skip to content

[Bug]: getVectorLayers: unsafe JSON handling in vector source loader #353

Description

@Athina09

Page / Route

Homepage (/)

Selected Location

No response

Bug Description

Summary

getVectorLayers can throw when a WFS request fails because readFeatures is called with null/invalid JSON.

Problem

In src/actions/getVectorLayers.js, the vector source uses a custom loader that fetches the WFS URL. When the response is not OK, the code returns null from the first .then, but the next .then still runs and calls:

vectorSource.getFormat().readFeatures(json)

If json is null (or otherwise invalid), this can throw and break layer loading, instead of failing gracefully.

Expected behavior

  • If the HTTP request fails or returns a non-OK status, the loader should not attempt to parse features.
  • The layer should fail quietly (log a warning) without throwing.

Suggested fix

Add a guard before parsing:

.then((json) => {
  if (!json) return;
  vectorSource.addFeatures(vectorSource.getFormat().readFeatures(json));
})

### Steps to Reproduce

_No response_

### Expected Behavior

_No response_

### Filters Applied

_No response_

### Screenshots / Logs

_No response_

### Browser

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions