Two things in your exception:
Quote:
Unhandled promise rejection
This can be resolved by wrapping your code with a
try...catch
block that will help you capture the exception and check the details. When working with exceptions, it is always recommended to use the exception handler because implicit exception handling is discouraged in JavaScript.
Quote:
TypeError: undefined is not an object (evaluating 'result['counter']['serviceNumber']')
For this one, I think the problem is with the
counter
argument. One of the reasons this is happening is because your
result
object does not contain a
counter
—thus, reading the
serviceNumber
is not possible because the field
counter
is
undefined
.
Tip: When working with an API that does not guarantee the data structure (for example, often provides null values or ignores providing the unavailable data), you must always use
if...else
to verify that the objects are not
null
or
undefined
.