How to pop up an error message in the front end with an Ajax request?

return render_json_error(
            'Cannot perform the pin operation.',
            status: 402
          )

Using the render_json_error method, how can I display an error message on the frontend?

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);
1 Like