Release/epic 7#168
Closed
Benevanio wants to merge 7 commits into
Closed
Conversation
…d session management
Signed-off-by: Benevanio <benevaniosantos930@gmail.com>
#163) …d session management
Benevanio
requested review from
hltav,
lima300 and
nayarakarinesilva
as code owners
July 11, 2026 19:44
Signed-off-by: Benevanio <benevaniosantos930@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Esta PR padroniza o tratamento/serialização de erros (frontend e backend) e ajusta/expande a suíte de testes para validar o novo envelope { code, message, details? }, incluindo validação via middleware e propagação consistente de AppError/ApiError.
Changes:
- Frontend: adiciona
ApiError+parseApiErrore integra o parser via interceptor do Axios e via fetch no domínio de Auth. - Backend: introduz
AppError, centraliza validação com middlewarevalidate(Zod) e centraliza serialização noerrorHandler. - Testes: atualiza testes unitários/integração para validar códigos (
UNAUTHORIZED,NOT_FOUND,CONFLICT, etc.), detalhes de validação e cenários de ownership.
Reviewed changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/tests/unit/utils/apiError.test.ts | Novos testes unitários para parseApiError e envelopes/legado/fallback. |
| frontend/tests/unit/services/auth.service.test.tsx | Ajusta testes para envelope padronizado e valida ApiError/code. |
| frontend/src/shared/lib/apiError.ts | Implementa ApiError e parseApiError para padronizar parsing no frontend. |
| frontend/src/shared/lib/apiClient.ts | Adiciona interceptor do Axios para rejeitar com ApiError padronizado. |
| frontend/src/domains/auth/infrastructure/authApi.ts | Troca erros genéricos por parseApiError nas chamadas fetch do Auth. |
| backend/tests/unit/modules/users/users.service.test.ts | Atualiza asserts para AppError (code/statusCode/message). |
| backend/tests/unit/modules/users/user.controller.test.ts | Ajusta controller tests para exceções AppError e propagação de erros. |
| backend/tests/unit/modules/savedJobs/savedJobs.service.test.ts | Amplia cobertura: ownership, transições de status e códigos padronizados. |
| backend/tests/unit/modules/savedJobs/savedJobs.controller.test.ts | Ajusta testes para controllers lançarem AppError e propagarem erros. |
| backend/tests/unit/modules/auth/credentials.service.test.ts | Atualiza testes para AppError em conflict/unauthorized/notFound. |
| backend/tests/unit/modules/auth/credentials.controller.test.ts | Remove mocks de Zod e valida fluxo com AppError + middleware de validação. |
| backend/tests/unit/modules/auth/auth.controller.test.ts | Simplifica testes, removendo caso de validação direta no controller. |
| backend/tests/unit/middleware/withSession.test.ts | Novo teste unitário para middleware withSession. |
| backend/tests/unit/middleware/validate.test.ts | Novo teste unitário para middleware validate (body/query/params). |
| backend/tests/unit/middleware/requireAuth.test.ts | Novo teste unitário para requireAuth retornando envelope padronizado. |
| backend/tests/unit/middleware/errorHandler.test.ts | Expande testes do handler: AppError, ZodError e details por env. |
| backend/tests/unit/lib/errors.test.ts | Novos testes para factories/toJSON/fromZodError do AppError. |
| backend/tests/unit/app.test.ts | Ajusta asserts para envelope { code, message } em erro de CORS. |
| backend/tests/integration/routes/user.routes.test.ts | Verifica envelope/details para validações (ex.: username inválido). |
| backend/tests/integration/routes/savedJobs.routes.test.ts | Atualiza integração para ownership, transições e envelopes padronizados. |
| backend/tests/integration/routes/auth.routes.test.ts | Atualiza integração para validação Zod via middleware e AppError. |
| backend/tests/integration/middleware/authGuards.test.ts | Novos testes de rotas protegidas (requireAuth) e exceções permitidas. |
| backend/src/routes/users.routes.ts | Encaminha promises com .catch(next) e aplica validate nos payloads. |
| backend/src/routes/savedJobs.routes.ts | Encaminha promises com .catch(next) e aplica validate nos payloads. |
| backend/src/routes/auth.routes.ts | Aplica validate para params/body e encaminha erros via .catch(next). |
| backend/src/modules/users/users.service.ts | Troca Error genérico por AppError.notFound em cenários de ausência. |
| backend/src/modules/users/users.controller.ts | Remove try/catch local e passa a lançar AppError (handler central). |
| backend/src/modules/users/schemas/user.schemas.ts | Exporta createPreferencesSchema e tipos inferidos. |
| backend/src/modules/savedJobs/schemas/savedJobs.schemas.ts | Introduz schemas Zod para create/update (inclui enum status + appliedAt). |
| backend/src/modules/savedJobs/savedJobs.service.ts | Troca Error genérico por AppError (conflict/notFound). |
| backend/src/modules/savedJobs/savedJobs.controller.ts | Remove validação Zod inline/handler local e lança AppError. |
| backend/src/modules/auth/credentials.service.ts | Troca Error genérico por AppError (conflict/unauthorized/notFound). |
| backend/src/modules/auth/credentials.controller.ts | Remove validação/try-catch no controller; deixa handler/middleware centralizar. |
| backend/src/modules/auth/auth.controller.ts | Remove validação Zod no getUrl (assume validação em rota) e tipa provider. |
| backend/src/middleware/validate.ts | Novo middleware para validar body/query/params e converter ZodError em AppError. |
| backend/src/middleware/requireAuth.ts | Retorna envelope padronizado com AppError.unauthorized().toJSON(). |
| backend/src/middleware/errorHandler.ts | Centraliza serialização de AppError e conversão de ZodError + env gating de details. |
| backend/src/lib/errors.ts | Implementa AppError (factories, fromZodError, toJSON) e type guards. |
Comment on lines
9
to
13
| @@ -7,8 +13,25 @@ export function errorHandler( | |||
| _next: NextFunction, | |||
Comment on lines
+32
to
+35
| const details = isProduction() | ||
| ? undefined | ||
| : { cause: error.message || "unknown" }; | ||
| const appError = AppError.internal("Erro interno.", details); |
Comment on lines
110
to
+112
| const payload = await parseResponse(response); | ||
|
|
||
| if (!response.ok) { | ||
| throw createError(payload, "Falha ao obter URL de autenticacao Google."); | ||
| } | ||
|
|
||
| return payload.url; | ||
| throwIfNotOk(response, payload, "Falha ao obter URL de autenticacao Google."); | ||
| return (payload as { url: string }).url; |
Comment on lines
120
to
+122
| const payload = await parseResponse(response); | ||
|
|
||
| if (!response.ok) { | ||
| throw createError(payload, "Falha ao obter URL de autenticacao Github."); | ||
| } | ||
|
|
||
| return payload.url; | ||
| throwIfNotOk(response, payload, "Falha ao obter URL de autenticacao Github."); | ||
| return (payload as { url: string }).url; |
Comment on lines
+132
to
+136
| response, | ||
| payload, | ||
| "Falha ao obter URL de autenticacao LinkedIn.", | ||
| ); | ||
| return (payload as { url: string }).url; |
Comment on lines
+45
to
+62
| function asCode(value: unknown): ApiErrorCode | undefined { | ||
| const code = asString(value); | ||
| if (!code) return undefined; | ||
|
|
||
| const known: ApiErrorCode[] = [ | ||
| "VALIDATION_ERROR", | ||
| "UNAUTHORIZED", | ||
| "FORBIDDEN", | ||
| "NOT_FOUND", | ||
| "CONFLICT", | ||
| "INTERNAL_ERROR", | ||
| "UNKNOWN_ERROR", | ||
| ]; | ||
|
|
||
| return known.includes(code as ApiErrorCode) | ||
| ? (code as ApiErrorCode) | ||
| : "UNKNOWN_ERROR"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR aberta Pelo @SilvioFelix32 para aprimoraramento dos testes