Fix undefined behavior issue
send back an error if there's an encryption failure