Nikons from that era (D40, D50, D60, etc) have a couple of things that are fairly well known to cause the dreaded 'Shutter Error" and/or locked up mirror.
The first is that the main drive wheel for the shutter/mirror cocking mechanism is dirty or needs lubrication. This wheel can be accessed on many Nikon cameras by removing the floor plate of the camera. It's the red wheel visible through a cutout in the metal chassis. A drop or two of grease (I prefer white lithium) applied to the wheel with a toothpick should do the trick. You want a fairly thick lubricant for this wheel, but just a tiny dab will do. Spread it around evenly over the entire circle of the wheel. (Please note: WD40 is NOT a lubricant. It is a penetrating cleaner and water dispersant.) DO NOT spray grease from a can directly into your camera - it can get in a lot of places you don't want it to go! This video shows how to do the same thing with a D40, but most of the Dx0 models from that time are very similar. (Note: he uses spray directly, but I do not recommend doing so!)
The other problem area is also one that just needs a bit of lubrication but is in an area harder to access. Disassembling the camera to access the area is probably beyond all but the most capable do-it-yourselfers. But there is a trick to getting a drop of machine oil where it needs to be without taking anything apart. Use a straightened paper clip to place one tiny drop of oil on the post that is the pivot around which the shutter and mirror cocking mechanisms rotate. Here is an "exploded" diagram of the area. #208 is the aperture control lever that is visible when your lens is removed.
And here is how you reach it without taking anything apart.
GENTLY pull the aperture linkage lever (indicated by the blue arrow) down and hold it while inserting a straightened paper clip with a drop of mineral oil on the end into the area marked by the blue arrow and place the drop on the point where the other end of the aperture lever pivots. I use sewing machine oil for this one. If the camera is held in portrait orientation with the shutter button end up, the oil will lubricate the post that both the shutter and mirror cocking mechanisms also pivot, as they are all in there very close together. The aperture lever is spring-loaded, and you don't want to let it slip out from under your finger and bounce back unimpeded. That could allow the spring to become unseated and then the camera will need to be disassembled to be repaired!
After you've oiled and lubed your camera, cycle the shutter a few times to spread it around a little. If it tests OK you're good to go. If you're still getting the error or stuck mirror, then it's probably time for a trip to a repair shop/service center or, if the cost would be as much or more than the camera is worth, time for another camera.
Or, for easier access to the red wheel you could just dremel a hole in the right spot of the camera's bottom cover. LOL!