Web Development

O alerta que dizia Error: {}

A

Admin User

Author

Jul 28, 2026
13 min read
10 views
O alerta que dizia Error: {}

Summary

Por que a mensagem some

JSON.stringify(err); // '{}'

Pausa: o que é "não-enumerável"?

Object.defineProperty(user, "senha", { value: "123456", enumerable: false, // ← a única diferença });

user.senha; // '123456' — existe e funciona normalmente Object.keys(user); // ['nome'] — mas não aparece na lista JSON.stringify(user); // '{"nome":"Ana"}' "senha" in user; // true — e ainda assim está lá

Onde isso pega você

O caso pior é quando sobra alguma coisa

JSON.stringify(err); // '{"code":"ERR_BAD_RESPONSE","config":{"url":"https://api.exemplo.com/pedidos"}}'

JSON.stringify(new AppError("saldo insuficiente", "E_BALANCE")); // '{"name":"AppError","code":"E_BALANCE"}'

Spread e Object.assign não salvam

Se você usa Error.cause, ele vai junto

JSON.stringify(outer); // '{}'

Como resolver

const out = { name: err.name, message: err.message, stack: err.stack };

// props que a lib pendurou (code, status, config...) — essas são enumeráveis for (const key of Object.keys(err)) out[key] = err[key];

if (err.cause) out.cause = serializeError(err.cause);

return out; };

serializeError(outer); // { // name: "Error", // message: "falha ao processar pedido", // stack: "Error: falha ao processar pedido\n at ...", // code: "E_PEDIDO", // cause: { name: "Error", message: "timeout of 30000ms exceeded", stack: "..." } // }

JSON.stringify({ msg: "falhou", error: err }, replacer); // '{"msg":"falhou","error":{"name":"Error","message":"boom","stack":"..."}}'

JSON.stringify(new AppError("agora vai")); // '{"name":"AppError","message":"agora vai","stack":"..."}'

O retry que nunca aconteceu

E não, a correção não é aumentar o timeout

total = 3 × 8 + 2 × 2 = 28s < 30s do chamador ✓

O que eu tirei disso

Cinco minutos pra checar na sua stack

Source

This article discusses content originally published by at Dev.to.

Read the original article

Share this article

Written by Adil Sher

Full stack developer building high-traffic platforms, AI services, and custom web applications. Explore my portfolio, learn about my background, or get in touch.

Related Articles

I Pushed Code for Years Without Understanding What Happened Next
Web Development Aug 3

I Pushed Code for Years Without Understanding What Happened Next

I remember the exact moment I realized I had no idea how my CI pipeline actually worked. I was debugging a flaky test in our staging environment, and a senior developer asked me: "Where is this test running?" I said "GitHub Actions." He asked: "On what machine?" Silence. I honest...