#createError statusMessage vs message

1 messages · Page 1 of 1 (latest)

glacial portal
#

with createError what is the difference between statusMessage and message?

potent geyserBOT
#

Hi @glacial portal. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

The difference between the statusMessage and message properties in createError is primarily about their intended use and content:

  • statusMessage: This property is meant for short, HTTP-compliant status texts, such as "Not Found" or "Unauthorized". It should only contain horizontal tabs, spaces, and visible ASCII characters ([\t\u0020-\u007E]). The value of statusMessage will be sanitized by h3, and using longer or non-ASCII content will trigger a warning. It is suitable for brief, standard status descriptions that might be shown in HTTP responses or UI status badges. For example:

    throw createError({ statusCode: 404, statusMessage: 'Not Found' })
    
  • message: This property is intended for longer, more descriptive error messages. You should use message for detailed explanations, multi-line content, or any text that goes beyond a short status. This is the property to use for user-facing error details or logs. For example:

    throw createError({ statusCode: 404, message: 'The page you are looking for does not exist.' })
    

Important: If you use statusMessage for longer or non-ASCII messages, you will get a warning, and the value will be sanitized. Always use message for detailed or user-facing error information, and reserve statusMessage for short, HTTP-compliant texts only. This distinction is documented in both the Nuxt and h3 documentation and has been clarified due to developer confusion and warnings in recent versions createError: The statusMessage parameter causes a deprecation warning docs: Clarify statusMessage limitations.

#

In summary:

  • Use statusMessage for short, HTTP status texts.
  • Use message for detailed error descriptions.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@glacial portal Kapa.ai is still learning and improving, please let me know how I did by reacting below.

mystic geode