-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: using neverthrow
to explicitly handle errors in UserController
#371
Conversation
Drafting this PR to change how controllers call services; they should be called step by step for additional clarity, checking errors every step of the way as discussed with Yuan |
import { Router } from 'express' | ||
|
||
import * as UserController from './user.controller' | ||
import * as UserRules from './user.rules' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a new preference for inlining the rules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh, they are just used in this place, and having to refer to yet another *.rules
file when in *.routes
files seems a little annoying when developing or reviewing
It has now been replaced by ApplicationError
Sorry, sticky fingers. Not refactored to check for errors every step of the way yet. |
Add error handling every step of the way. |
# Conflicts: # src/app/factories/sms.factory.js # src/app/modules/auth/__tests__/auth.controller.spec.ts # src/app/modules/auth/__tests__/auth.routes.spec.ts # src/app/modules/auth/auth.utils.ts # src/app/modules/user/__tests__/user.controller.spec.ts # src/app/modules/user/user.controller.ts # src/app/services/sms/sms.service.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some remaining questions about backwards compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
èl géê tëē ėm
Problem
Similar to #332, this is an extension PR for #142 to implement explicit error handling to the endpoints.
Solution
Improvements:
neverthrow
's FP-likeResult
class to return either successok
s orerror
tracks for entireUser
module endpointstest
root import so test imports are less messycelebrate
rules inuser.routes
like auth routesMalformedOtpError
, it has now been replaced byApplicationError
utils/hash
containing the neverthrown versions ofbcrypt.hash
andbcrypt.compare
Tests
express-auth
helper function to get authed session for integration tests that requires the user to be logged in.modules/user/ __test__
directoryUserService
andSmsService
/user
routeSmsService
tests using Jest and TypeScript