@oondemand/oon-core-back 0.4.2 → 0.4.3
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.
package/package.json
CHANGED
package/src/api/auth.routes.js
CHANGED
|
@@ -36,17 +36,28 @@ function translateProviderError(error) {
|
|
|
36
36
|
if (error instanceof GenericError) return error;
|
|
37
37
|
const timedOut = error.code === "ECONNABORTED";
|
|
38
38
|
const statusCode = timedOut ? 504 : error.response?.status || 502;
|
|
39
|
-
const
|
|
39
|
+
const providerError = error.response?.data?.error;
|
|
40
|
+
const envelope = providerError && typeof providerError === "object"
|
|
41
|
+
? providerError
|
|
42
|
+
: {};
|
|
43
|
+
const message = envelope.message || error.response?.data?.message || (timedOut
|
|
40
44
|
? "A Central de Ativações não respondeu dentro do prazo."
|
|
41
45
|
: "Não foi possível autenticar o usuário na Central de Ativações.");
|
|
42
|
-
return new GenericError(message, {
|
|
46
|
+
return new GenericError(message, {
|
|
47
|
+
statusCode,
|
|
48
|
+
code: envelope.code || error.response?.data?.code,
|
|
49
|
+
details: envelope.details ?? error.response?.data?.details ?? null,
|
|
50
|
+
});
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
function tenantForLogin(req, instance) {
|
|
46
54
|
const tenancyModel =
|
|
47
55
|
ctx.config.tenancyModel || ctx.config.ecosystem?.tenancyModel;
|
|
48
56
|
if (tenancyModel === "multi_tenant") {
|
|
49
|
-
|
|
57
|
+
// Uma instância compartilhada não pertence ao tenant que a ativou
|
|
58
|
+
// originalmente. Sem seleção explícita, a Central de Ativações resolve o
|
|
59
|
+
// único tenant elegível ou devolve as opções disponíveis.
|
|
60
|
+
return req.headers[TENANT_HEADER];
|
|
50
61
|
}
|
|
51
62
|
return instance.tenantId;
|
|
52
63
|
}
|
|
@@ -58,10 +58,18 @@ const errorMiddleware = (error, req, res, next) => {
|
|
|
58
58
|
const details = error.details && typeof error.details === "object" && !Array.isArray(error.details)
|
|
59
59
|
? { ...error.details, ...(requestId ? { requestId } : {}) }
|
|
60
60
|
: error.details;
|
|
61
|
+
const envelope = error.code
|
|
62
|
+
? {
|
|
63
|
+
code: error.code,
|
|
64
|
+
message: error.message,
|
|
65
|
+
...(details !== null && details !== undefined ? { details } : {}),
|
|
66
|
+
...(requestId ? { requestId } : {}),
|
|
67
|
+
}
|
|
68
|
+
: details;
|
|
61
69
|
return helpers.sendErrorResponse({
|
|
62
70
|
res,
|
|
63
71
|
statusCode: error.statusCode,
|
|
64
|
-
error:
|
|
72
|
+
error: envelope,
|
|
65
73
|
message: error.message,
|
|
66
74
|
});
|
|
67
75
|
}
|