import axios from 'axios';
import type { App, ComponentPublicInstance } from 'vue';

export default function setupErrorReport(app: App, baseUrl: string) {
  if (!baseUrl) {
    return;
  }
  app.config.errorHandler = (
    err: unknown,
    instance: ComponentPublicInstance | null,
    info: string,
  ) => {
    axios.post(`${baseUrl}/report-error`, {
      err,
      instance,
      info,
    });
  };
}
