I think the error messages in all these throws could be improved. Here, for example, the error text could be:
0throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Script import failed due to problem importing private key %s.", EncodeSecret(key));
As it is, it’s not clear that failing to import this key also causes the script to not be imported. Same comment for failures to import pubkey below.
It’s a bit of a shame that this operation isn’t atomic and failing to import one key or script will result in the prior keys being imported but the following keys not being imported. Might be worth adding a comment somewhere to highlight that?