Is there a way to create a toast error message on the frontend from within a doc, or field hook?

default discord avatar
last month

I want to ensure that a page can only be created from the default locale, as I need to ensure it's default pathname is created, before any sort of localized pathname is added.

I'd like to do something like this:

  if (operation === "create" && isDefaultLocale) {
    throw new Error("Pages must be created within the default locale.");

However, that error only shows in the server's console. Is there a way I can send that error message to the client, in order to be displayed within a toast message/notification, instead of saying a non-descriptive "Something went wrong"?

  • discord user avatar
    Payload Team
    last month

    In order for an error to show up in the toast notification it must have the


    property on it.

    The easiest way to do this would be to extend our existing


    with a new class, then throw that class. Here is an example:

    import { APIError } from 'payload/errors'
    class MySpecialError extends APIError {
      constructor(message: string) {
        super(message, 400, undefined, true)

    The 4th parameter is the



    Then throw as you'd expect

    throw new MySpecialError('Cannot create in default locale')
  • default discord avatar
    last month

    Thank you 👍🏻

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.