Skip to content

Error when calling service with port  #8

@waghcwb

Description

@waghcwb

I'm trying to make a request to an ip with a port, eg: http://10.113.132.457:32001

But when I make the request I get the following error:
Unhandled promise rejection TypeError: "Expected "32001" to be a string"

I've tried removing the port from the url and add again on a hook but without success

hooks: {
  before({ payload, next }) {
    const url = new URL(payload.url)
    url.port = '32001'
    payload.url = url.toString()
    next(payload)
  }
}

I've the following structure for the services

export const BaseService = new ApiService({
  adapter: xhr, // ie11
  url: process.env.SERVICE_URL,
  mode: 'cors',
})

export const AvailabilityService = {
  url: 'checkAvailability',
  children: [
    {
      name: 'getAvailability',
      method: 'GET'
    }
  ],
  
  hooks: {
    before({ payload, next }) {
      const url = new URL(payload.url)
      url.port = '32001'
      payload.url = url.toString()
      next(payload)
    }
  }
}

And then in my component

const { success, result } = await api('getAvailability').doSingleRequest({
  query: params
})

I'm doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions