You have some issues in your code that need to be addressed:
- Make sure your return type is not void if you are returning data
- Ensure all code paths return a result
- If you call
await disable(product)
, there may not be any output without an error
- Logging should be at the appropriate level
- Avoid mixing Promise and async/await syntax when possible
- It's unclear where the
data
in your example comes from; make sure to specify this or pass the product instead
Consider revising your code like this:
async disable(product: Product): Promise<any> { // Specify expected type here
try {
const response = await this.axios.put(`products/update`, {data}); // Avoid mixing Promise and async/await syntax
return response.data; // Return response data directly
} catch (e) {
console.error(`error: ${JSON.stringify(error)}`);
throw e; // Rethrow error or return null if request fails
}
}
const result = await disable(product);
console.log(result); // Output result to check what you get
Here are some tips for troubleshooting similar issues in the future:
- In the browser, check the network tab for sent requests and responses
- Log extensively or use a debugger to track your code execution