In handleSyscall the variable v1 is used to refer to register 7 which is where the error code of the syscall is stored. However, the correct variable name of register 7 is a3. 
