'I have a getList method that receives parameters, but that method is used in 2 different pages. And I get an error in one of them. VUE JS .NET

good night everyone. I have the following question. I have a getList method created, which receives an articuloTipoId parameter. The issue is that this method, I had not realized that I use it on 2 screens. This is my getList method:

    /// <summary>
    /// Listado completo de objetos.
    /// </summary>
    [HttpGet("getList/{articuloTipoId}")]
    public async Task<ActionResult<List<Articulo>>> GetList(int? articuloTipoId)
    {
        string[] _include = { nameof(Articulo.CondicionIva), nameof(Articulo.Rubro), nameof(Articulo.ArticuloTipo), nameof(Articulo.UnidadMedida) };
        var result = await _articuloServices.GetListAsync(a => a.Id > 0
                                                            && (articuloTipoId == null || a.ArticuloTipoId == articuloTipoId)
                                                            , _include);
        return result;
    }

And I use it on these screens. In this function the method passes well. (I use the articuloTipoId to filter). Here everything is going well for me. Filter by the id that I have passed.

getList() {
  const articuloTipoId = this.articuloTipo != null ? this.articuloTipo : "";
  console.log(articuloTipoId)
  Swal.fire({
    title: "Espere unos momentos ...",
    showConfirmButton: false,
  });
  this.articuloServices
    .getList(articuloTipoId)
    .then((data) => {
      Swal.close();
      this.list = data;
    })
    .catch((error) => {
      Swal.close();
      this.showError(error.response.data);
    });
},

The problem arises because I had not realized that I use it on another screen. Then it starts throwing errors at me. Because what I need is to somehow use the same method in both. But in the other try to put null, empty... But I can't find a way to not throw the error.

getList() {
            Swal.fire({ title: 'Espere unos momentos ...', showConfirmButton: false });
            this.articuloServices
                .getList()
                .then((data) => {
                    Swal.close();
                    this.list = data;
                })
                .catch((error) => {
                    Swal.close();
                    this.showError(error.response.data);
                });
        },

The solution I am looking for is that the code is above, find a way so that it does not throw me that articuloTipoId is undefined, since it breaks the call to the method. Below I attach an image of the error that I get.

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source