You can get sqlplus to return an error code by using the WHENEVER SQLERROR
https://docs.oracle.com/en/database/oracle/oracle-database/21/sqpug/WHENEVER-SQLERROR.html
https://stackoverflow.com/a/59913172/3715973