I’m not sure what the whole context is, but I believe you can do this:
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
try {
// ...
} catch (e) {
popupAjaxError(e);
}
// OR
ajax("...") // Some function
.then(() => {
// ...
})
.catch(popupAjaxError);