Web Development

O alerta que dizia Error: {}

A

Adil Sher

Author

Jul 28, 2026
13 min read
7 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

Stop Selling Your Code. Start Selling Solutions.
Web Development Sep 10

Stop Selling Your Code. Start Selling Solutions.

I've been grinding as a freelancer in Islamabad for five years now, and I've made every mistake in the book. I've spent weeks perfecting a portfolio that nobody reads. I've engaged in architecture debates with CTOs that went nowhere. I've underbid jobs and overworked myself becau...