jsbaseclass
Version:
A lightweight JavaScript base class for logging, event handling, and browser detection. Designed to simplify common tasks in frontend development.
34 lines (31 loc) • 1.1 kB
JavaScript
class ClassAxios extends JsBaseClass {
async handle() {
await this.getData();
await this.getNonExistsData();
}
async getData() {
try {
this.console.info(`1️⃣ Before Get Data`);
const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1');
this.console.log(`✅ Get Data`, response.data);
} catch (error) {
this.console.log(`🚨 ${error.message}`, error);
} finally {
this.console.log(`2️⃣ After Get Data`);
}
}
async getNonExistsData() {
try {
this.console.info(`1️⃣ Before Get Non Exists Data`);
const response = await axios.get('https://not-exists/json/1');
this.console.log(response.data);
} catch (error) {
this.console.log(`🚨 ${error.message}`, error);
} finally {
this.console.log(`2️⃣ After Get Non Exists Data`);
}
}
}
// See more: // https://axios-http.com/docs/req_config
window.objAxios = new ClassAxios();
objAxios.init();