Using the async and await syntax when handling native Promises is standard, and leads to more readable and understandable code. Additionally, I moved the copied = true statement so it only executes on success rather than on success or failure.
Without a testing framework, however, this implementation is difficult to test. I don't want to be presumptuous or rude, so, I didn't do that for you. But, I would highly suggest adding tests.
Using the
async
andawait
syntax when handling native Promises is standard, and leads to more readable and understandable code. Additionally, I moved thecopied = true
statement so it only executes on success rather than on success or failure.Without a testing framework, however, this implementation is difficult to test. I don't want to be presumptuous or rude, so, I didn't do that for you. But, I would highly suggest adding tests.