Web Development

O alerta que dizia Error: {}

A

Adil Sher

Author

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

Why I'm Done Selling Clients Off-the-Shelf Themes
Web Development Nov 2

Why I'm Done Selling Clients Off-the-Shelf Themes

I had this conversation last month with a real estate agent in Rawalpindi. She wanted a website, found a "premium" template on ThemeForest, and asked if I could just install it. The template looked polished, smooth animations, modern design, the works. I said yes, and three weeks...

Why I'm Rethinking How We Handle AI in Production Apps
Web Development Nov 1

Why I'm Rethinking How We Handle AI in Production Apps

Last month, I was sitting in a standup meeting when someone asked how we'd handle our LLM API if the provider went down. The room went quiet. We'd built our entire feature around OpenAI's reliability, with barely a fallback in sight. That conversation stuck with me, mostly because...

Stop Pretending Your RAG System Knows What It Doesn't
Web Development Oct 31

Stop Pretending Your RAG System Knows What It Doesn't

Last month, a client asked me to build a "smart document search" for their internal knowledge base. I nodded, quoted them a timeline, and started architecting the usual suspects: vector embeddings, semantic search, a language model API call. Two weeks into development, during a d...