exit without an argument uses the exit status of the preceding command. That's OK for the first case, but in the second case you should be exiting with a non-zero exit status (1 is OK for non-specific errors), not the 0 you get from the preceding echo.
exit_script()
{
if [[ $? -eq 0 ]] ; then
echo "exit from script with success" >&2
exit # or exit 0, if you want to be specific
else
echo "exit with error..." >&2
exit 1
fi
}
You probably want the messages to go to standard error, but if not, just remove the >&2 that I added to each call to echo.
If you want to exit with the same exit status that you are testing, you'll need to save it first.
exit_script()
{
status=$?
if [[ $status -eq 0 ]] ; then
echo "exit from script with success"
else
echo "exit with error..."
fi >&2
# Now you can just make one, all-purpose call to exit
exit $status
}