Skip to content

🐞 Bug: ERR_BAD_REQUEST error connecting to http://localhost:8581/api/config-editor/ui/plugins/hide-updates-for #199

@justjam2013

Description

@justjam2013

Checking the API in Swagger, /api/config-editor/ui/plugins/hide-updates-for is a PUT call, not a GET call, therefore no values will ever be returned.

Image

Therefore the call fails with ERR_BAD_REQUEST, because no payload is sent to the API endpoint which expects an array:

[
    "homebridge-plugin-name"
]

This piece of code needs to be rethought as it is using the wrong API endpoint in the wrong way.

Looking at the code, a GET call is made to the API, so any code fix is just catching the inevitable errors generated by the bad code:

  public async getIgnoredPlugins(): Promise<Array<string>> {
    if (this.isConfigured()) {
      try {
        this.log.debug('Calling /api/config-editor/ui/plugins/hide-updates-for API endpoint')
        const result = await this.makeCall('/api/config-editor/ui/plugins/hide-updates-for')

        // Validate the response format
        if (!Array.isArray(result)) {
          this.log.warn(`Unexpected response format from ignored plugins API: ${typeof result}, expected array`)
          return []
        }
        ...
  }
  ...
  private async makeCall(apiPath: string): Promise<any[]> {
    return axios
      .get(this.baseUrl + apiPath, {
        headers: {
          Authorization: `Bearer ${this.getToken()}`,
        },
        httpsAgent: this.httpsAgent,
        lookup: this.cacheable.lookup,
      })
      .then((response) => {
        this.log.debug(`${this.baseUrl + apiPath}: ${JSON.stringify(response.data)}`)
        if (!Array.isArray(response.data)) {
          return [response.data]
        }
        return response.data
      })
      .catch((error) => {
        // At this point, we should have exhausted the retries

        this.log.error(`${error.code} error connecting to ${this.baseUrl + apiPath}`)

        return []
      })
  }

The call

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions