refac: simplify error treatment