API Performance - Frontend

Standards

  1. Always attempt to validate input before sending
  2. Make as few assumptions about data being available as possible. What if a a value is undefined?
  3. Use await/async as described below.
  4. Use regular error handling

Example request

async task_list_api() { this.loading = true try { const response = await axios.post(`/api/v1/job/${this.job_id}/task/list`, { 'date_from': this.date ? this.date.from : undefined, 'date_to': this.date ? this.date.to : undefined, 'job_id': this.job_id, 'mode_data': this.mode_data, 'incoming_directory_id': this.incoming_directory ? this.incoming_directory.directory_id : undefined, 'status': this.task_status }) if (response.data.log.success == true) { this.task_list = response.data.task_list this.pending_initial_dir_sync = response.data.pending_initial_dir_sync; } return response } catch (error) { console.log(error); return false; } finally { this.loading = false } },

Did this page help you?