Well, 3 years later this still appears to be an issue. What I see at the client is the MiniMongo error that contains the message I need to determine what happened in client code. But that is immediately followed by an internal server error, which is the one actually returned to my code.
The server does see the correct message, but that does not help me put up a toast at the client.
Well, as far as I can tell, an insert error cannot be issued in MiniMongo simply because it operates on subsets of the data, so it must make the round trip to the server to attempt it there.
The internal server error appears to come from there being no code in MiniMongo to hoist obvious errors like “_id already exists” on an insert command. This should come back as a Mongo error with that code or text available for parsing.
Presumably, to get proper error messages we are forced to make the round trip ourselves with a method call, which I consider massive overhead that is unnecessary. It is a surprisingly unfinished area so late in Meteor’s history. But I suppose it is at least solvable if you don’t mind writing unnecessary code.
It’s not really “unfinished”, it’s an unusual case - if you are using Random.id() the likelihood of a conflict is extremely small, if you are generating your own ID’s it’s your responsibility to ensure they are unique - there are other edge cases where you get this error, for example non _id unique keys. In general, any verification done on the server can also be done on the client (schema, security, etc) so you can avoid this problem. The reason the server returns a 500 error is to avoid leaking errors to the client that are not explicitly created. Without this it’s possible for the server to throw an error “Mongo connection to mongodb://admin:password@mysecrethost.com failed” - so in general it’s a good thing!