Fix badtoken handling broken by 7557dd39ed3

7557dd39ed3 make the badtoken handling code unreachable. Revert that
change, and fix the rest of the function to deal with the possibility
that editApi is undefined. Let handling of the read-only mode error
and any other errors fall through to the bottom of the function.

Change-Id: I0673f2bb629e5cc9449675c1074d283e3926e1d5
Merge "Fix badtoken handling broken by 7557dd39ed3"