Skip to content

saveProject throws an error when a network request fails #4276

Description

@slash-init

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting Maintainer ApprovalNeeds review from a maintainer before moving forwardBugError or unexpected behaviors

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions