processing / processing/p5.js-web-editor

saveProject throws an error when a network request fails

Open Beginner friendly
#4,276 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting Maintainer Approval Bug
Dominant language
JavaScript
Stars
1.7k
Forks
1.7k
Avg merge
3d 4h
Merged PRs (30d)
8

Description

p5.js version

2.3.2

What is your operating system?

Linux

Web browser and version

firefox 153.0.1

Actual Behavior

When saving a project, if the request fails because of a network error, saveProject() throws a TypeError instead of handling the save failure normally.
the error is:
Cannot read properties of undefined (reading 'status')
this happens because the error handler assumes error.response always exists, but for network errors there is no response.

Expected Behavior

A network error while saving should be handled as a normal save failure without throwing another error.
The user should get the usual save failure handling instead of an unhandled/rejected promise.

Steps to reproduce
Steps:
  1. open an existing saved project and make some changes.
  2. disconnect the network or otherwise make the api request fail without returning an http response.
  3. try to save the project.
  4. saveProject() rejects with:

Cannot read properties of undefined (reading 'status')

Snippet:
apiClient
  .put(`/projects/${state.project.id}`, formParams)
  .catch((error) => {
    const { response } = error;

    if (response.status === 403) {
      // ...
    }
  });

for a network error, error.response is undefined, so accessing response.status throws.
a possible fix would be to check whether response exists before accessing response.status, and handle network errors as a normal save failure.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the saveProject() entry point and the apiClient.put() catch handler shown in the issue. Reproduce the failure by making the request fail without an HTTP response, then verify that the existing save-failure handling runs without an unhandled rejection or secondary TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.