Use $app->enqueueMessage instead of JError and SOME_ERROR_CODE