Skip to content

Throwing custom error object appears as [Object object] #61902

@carlos-dubon

Description

@carlos-dubon

Link to the code that reproduces this issue

https://github.com/carlos-dubon/nextjs-error-bug

To Reproduce

// app/page.tsx

async function getData(): Promise<number> {
    throw {
        message: 'MY CUSTOM ERROR',
        name: 'My new error',
        cause: 'custom error',
    };
   return 3;
}

export default async function Home() {
    const pageData = await getData();

    return (
        <div>{pageData}</div>
    );
}

Current vs. Expected behavior

Throwing a custom error object appears as [Object object] in my app/error.ts file. I get a digest but the error is still [Object object] so it isn't helpful at all. I need this because our apps use a common package for calling our apis, and i can't simply modify it to suit only our web app.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
Binaries:
  Node: 20.10.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.lockedstaleThe issue has not seen recent activity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions