How to throw messages when there is a duplicate entry

For now, the form is not submitted when there is a duplicate entry. Error messages only show up in terminal. But I want to throw an error message in web application. I have tried autoform hooks, but it did not work.

 AutoForm.hooks({
   addSubjectForm: {
     onSubmit: function (insertDoc) {
       if (customHandler(insertDoc)) {
         this.done();
       } else {
         this.done(new Error("Submission failed"));
       }
       return false;
     }
  }
});

The schema is shown below.

import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';

export const subject = new Mongo.Collection('subject');

const subjectSchema = new SimpleSchema({
  subjectCode:{
    type: String,
    label: "Subject Code",
    index:true,
    unique:true
  },
  subjectName:{
    type: String,
    label: "Subject Name",
    index:true,
    unique:true
  }
});

subject.attachSchema(subjectSchema);

So how to do this with autoform or is there any other methods? Thanks in advance.