Cydo
Explore posts from servers✅ Can't get HTTPS to work for my api deployment.
I am following the Microsoft docs https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-9.0&tabs=linux-ubuntu step by step and I get the point where you set up nginx everything works when I'm on http, but the second i try to make anything go to https everything breaks, the connections time out and I can't get anything to work, I have no idea why.
No working HTTPS
2 replies
Trying to understand proper error handling
I am trying to write my code to properly handle errors and I am getting so hyper fixated on it that I can't tell whether I'm making good decisions or not.
I have rewritten the way my code base handles errors several times and I'm not sure what the right approach is anymore.
I originally started using my own implementation of the result pattern, then realized I have this issue where the status code wasn't correct when returning errors, so I said maybe my implementation isn't that good so I looked for a library and settled on ErrorOr, but soon realized its the same issue, I dont understand how you can tell the "result pattern" that this error is a 401, 500, or 400 etc so I gutted that out and started writting my own custom exceptions and made a middleware that handles all the exceptions but now Im reading that you shouldn't throw errors when you now how to handle them and that throwing excessive erros will cause performance issues.
160 replies
✅ How can I take 2 existing repos (client and backend) and combine them?
I've always made my frontend and backends separate repos, and would like to instead make set it up where the frontend and client are both in the same repo. But it doesnt seem as simple as just creating a parent folder with 2 subfolders one for frontend and one for backend and then or am I wrong? I assumed you'd have one .gitignore in the root instead of a .gitignore in each subfolder? Or because how .net has solutions is it more complex?
39 replies
✅ When should you or shouldnt you return nested data in an api call?
Let's say I have a these tables in my database, Project, Members, Task, Comments and I want to return paginated data so a user can view all their projects, then view the tasks and members associated with the project and the comments associated with the individual tasks. Would you do this as all separate queries or do one query that returns all the data nested and paginated?
Here's my current thought process.
13 replies
✅ Having trouble handling errors when registering a new user
So my application is a .NET web api with a React front end, and im trying to handle all my errors on the backend during the register process and I dont seem to understand how errors are handled. When a user signs up im trying to account for all possible issues they could run into. For example wrong password length, missing special characters, uppercase, etc and then the same for email for example is it a valid email, is there any mistakes in the email for instance
test@test,com
as opposed to [email protected]
I noticed that modelstate is always valid with email part, but for password things seem to work.
the error that gets thrown when the email is not in a correct format actually comes from here var result = await _userManager.CreateAsync(user, registerRequestDTO.Password);
and it throws this error "Username 'test1@test,com' is invalid, can only contain letters or digits."
and I can't seem to figure out how to make it handle this error correctly so that it is in the format below, I don't think I can just hard code it because what if a different error is thrown, i want it to always come back in the format, Key: ['array of errors', '...' ]
like below.
But I'm not sure how to achieve that. This is what I set up for my code currently and that specific error always hits the ApplicationException
I'll attach the code in a gist since there is so much of it https://gist.github.com/CydoEntis/2d9160d6867651f8209214334779a3fe6 replies
✅ Unit of Work for just Repositories or Services as well?
When you create a unit of work and you add repositories inside of it so you aren't constantly newing up additional ones across your applications, should services also be added to the same unit of work? Another unit of work or not at all?
I don't see the harm in adding services to the unit of work so would that be a valid thing to do or will that cause issues somehow?
1 replies
✅ How to hide sensitive data, like database credentials api keys etc
I know you enter this stuff in your appsettings.json, but from what I can see your apisettings.json gets stored in your gitrepo, so is there something like a .env file in the .NET ecosystem where i can store everything in there omit it from git and then load that data into appsettings.json?
Everything I found so far is talking about setting the variables in an azure key vault or setting them inside of the terminal, am I missing something here? I'm just developing locally atm but even if i deploy this app, i dont think I will be using azure because of how expensive it is and would like to not use the key vault because of that, but at the same time i dont want any of this to be on my git repo for random ppl to potentially see as well.
16 replies