Added error handling but it only works for mandatory fiel (i.e name) and the
error message is weird.