@seedgrid/fe-core 2026.6.5 → 2026.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,6 +19,12 @@ export declare function isApiClientErrorLike(error: unknown): error is ApiClient
|
|
|
19
19
|
* Cai no `.message` do próprio erro só quando não há payload de problema.
|
|
20
20
|
*/
|
|
21
21
|
export declare function extractApiErrorMessage(error: unknown): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Mensagem amigável (pt-BR) para um HTTP status, usada quando o corpo do erro não
|
|
24
|
+
* traz mensagem própria. Exposta para fluxos `fetch` crus (que têm o
|
|
25
|
+
* `response.status` mas não um `ApiClientError`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function messageForHttpStatus(status: number): string;
|
|
22
28
|
/**
|
|
23
29
|
* Mensagem a partir de UM corpo já em mãos (objeto problem+json, ou string JSON que
|
|
24
30
|
* parseie em um). Texto simples não-JSON -> o próprio texto; objeto sem mensagem
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-errors.d.ts","sourceRoot":"","sources":["../../src/http/api-errors.ts"],"names":[],"mappings":"AAiCA,KAAK,kBAAkB,GAAG;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,kBAAkB,CAE7B;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"api-errors.d.ts","sourceRoot":"","sources":["../../src/http/api-errors.ts"],"names":[],"mappings":"AAiCA,KAAK,kBAAkB,GAAG;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,kBAAkB,CAE7B;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAcpE;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA2B3D;AASD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAMhE"}
|
package/dist/http/api-errors.js
CHANGED
|
@@ -16,15 +16,55 @@ export function extractApiErrorMessage(error) {
|
|
|
16
16
|
if (fromProblem) {
|
|
17
17
|
return fromProblem;
|
|
18
18
|
}
|
|
19
|
-
// Sem
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
if (
|
|
24
|
-
return
|
|
25
|
-
}
|
|
19
|
+
// Sem mensagem no corpo: muitos erros (401/403/404/5xx) vêm SEM corpo. Em vez de
|
|
20
|
+
// vazar o `.message` genérico do ApiClientError ("API request failed with status N"),
|
|
21
|
+
// devolve uma mensagem amigável do HTTP status (ex.: 403 -> "Acesso negado").
|
|
22
|
+
const status = httpStatusOf(error);
|
|
23
|
+
if (status != null) {
|
|
24
|
+
return messageForHttpStatus(status);
|
|
25
|
+
}
|
|
26
|
+
// Erro sem status (rede / hand-thrown): cai no próprio `.message`.
|
|
26
27
|
return pickString(readErrorMessage(error));
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Mensagem amigável (pt-BR) para um HTTP status, usada quando o corpo do erro não
|
|
31
|
+
* traz mensagem própria. Exposta para fluxos `fetch` crus (que têm o
|
|
32
|
+
* `response.status` mas não um `ApiClientError`).
|
|
33
|
+
*/
|
|
34
|
+
export function messageForHttpStatus(status) {
|
|
35
|
+
switch (status) {
|
|
36
|
+
case 400:
|
|
37
|
+
return "Requisição inválida.";
|
|
38
|
+
case 401:
|
|
39
|
+
return "Sessão expirada. Faça login novamente.";
|
|
40
|
+
case 403:
|
|
41
|
+
return "Acesso negado.";
|
|
42
|
+
case 404:
|
|
43
|
+
return "Recurso não encontrado.";
|
|
44
|
+
case 408:
|
|
45
|
+
case 504:
|
|
46
|
+
return "Tempo de resposta esgotado. Tente novamente.";
|
|
47
|
+
case 409:
|
|
48
|
+
return "Conflito com o estado atual do recurso.";
|
|
49
|
+
case 422:
|
|
50
|
+
return "Não foi possível processar os dados enviados.";
|
|
51
|
+
case 429:
|
|
52
|
+
return "Muitas requisições. Aguarde um momento e tente novamente.";
|
|
53
|
+
case 503:
|
|
54
|
+
return "Serviço temporariamente indisponível. Tente novamente.";
|
|
55
|
+
default:
|
|
56
|
+
if (status >= 500) {
|
|
57
|
+
return "Erro no servidor. Tente novamente.";
|
|
58
|
+
}
|
|
59
|
+
return "Não foi possível concluir a operação.";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function httpStatusOf(error) {
|
|
63
|
+
if (isRecord(error) && typeof error.status === "number") {
|
|
64
|
+
return error.status;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
28
68
|
/**
|
|
29
69
|
* Mensagem a partir de UM corpo já em mãos (objeto problem+json, ou string JSON que
|
|
30
70
|
* parseie em um). Texto simples não-JSON -> o próprio texto; objeto sem mensagem
|