I don't know the JS library, but at the REST API level you do this by doing a GET of /_active_tasks and looking for the task entry corresponding to your replication. It will have a property describing the current status and any error.
(If you search the group archive for '_active_tasks' you'll find some threads talking about the best way to do this.)
—Jens