Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Add plug to do board/user lookups and needed error responses. #17

Open
zorn opened this issue Sep 21, 2021 · 1 comment
Open

Add plug to do board/user lookups and needed error responses. #17

zorn opened this issue Sep 21, 2021 · 1 comment
Labels
enhancement New feature or request MVP1

Comments

@zorn
Copy link
Contributor

zorn commented Sep 21, 2021

Currently the JoinBoard.process_request/3 takes a user_id and a board_id as part of it's argument list. I keep flip flopping about this, if I should pass in an id or the User/Board.

My current thinking is that, the controller function should be more explicit, probably through a plug about doing lookups for the board and user. If the request is referencing a non-existent resource, then we should return a HTTP error code, showing an un-proccessable request -- this way the internal functions can have a tighter scope of responsibilities, and not have to constantly check for bad references to non-existent Users.

@zorn zorn added enhancement New feature or request MVP1 labels Sep 21, 2021
@zorn
Copy link
Contributor Author

zorn commented Oct 4, 2021

Right now JoinBoard.process_request/2 is called after an attempt to call Boards.get_board!(board_id) so I feel confident that if the board_id is not valid a 404 response will be sent.

Similarly we attempt to get user_id via user_id = Plug.Conn.get_session(conn, :user_id) -- the expectation is this will result in a nil value OR valid user_id. Technically it could result in an invalid user_id, I see this happen when I reset my local dev db but the browser cookie still has the old user id but I don't see this happening much once in production.

Having JoinBoard.process_request/3 return {:ok, user, board} or {:error, reason} just keeps the code simple. I suppose in a more bullet proof env I could return :board_not_found or :user_not_found but I'm going to skip that for now.

If we did add this in the future, I suppose the good user experience would be to show a 404 for missing board, or forward the user to a help page explaining they should reset their local cookies and try again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request MVP1
Projects
None yet
Development

No branches or pull requests

1 participant