You can trick it by echoing the exit code in your shell call:
run("./script.sh; echo EXIT_CODE=$?") do |ssh_channel, stream_id, output|
output, exit_code = output.split("EXIT_CODE=")
logger.important 'Error message 1' if exit_code == 1
logger.important 'Error message 2' if exit_code == 2
puts output
end