Hello,
whats wrong with this script, when I execute the Script with nodjs on Terminal it works, when I transpile it, the api-call will never run in Switch????
const axios = require("axios"); //JavaScript
import axios from "axios"; //TypeScript
...
try {
let result = await axios({method:"get", url:"https://url.com/api/v1/titles/" + objekt});
//do something with the result
} catch(error) {
//do something with the error
}
For more options and examples, see the axios documentation. When using the examples you find, always make sure not to use the .then callback functions. Remove them and await the axios call. It is as simple as that.
The interceptors will not provide any added value. If you are only interested in the body of the return regardless of success or error then this is where you will find it:
let body;
try {
let result = await axios({method:"get", url:"https://url.com/api/v1/titles/" + objekt});
body = result.data;
} catch(error) {
body = error.response.data;
}
//do something with the body