N
Nuxt4w ago
Mads

createError statusMessage vs message

with createError what is the difference between statusMessage and message?
4 Replies
kapa.ai
kapa.ai4w ago
Hi @Mads. 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' })

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.' })

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: ----------------------
kapa.ai
kapa.ai4w ago
<@335112909350895632> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Alif N
Alif N3w ago
@kapa.ai How do I retrieve the error on a page, for example, if I hit the endpoint using $fetch? What types of errors can be caught in a try catch?
dmarr
dmarr3w ago
You may need to change the accept header to application/json

Did you find this page helpful?