Try to post a screen shot of the error, but in the meantime go to settings > apps > camera > storage & clear cache & data for the camera & reboot. Test & see if you still get the error message.
If wiping cache & data for the camera didn't fix the problem. Go to the Samsung members app & click on "help" > "interactive" > and the Camera icon to test the camera.
If you still have problems, then you can try Booting into Recovery and wipe cache.
If you still have problems, then you can boot into recovery & factory reset BUT backup your phone with smart switch FIRST!
If a factory reset didn't fix the problem, then I'd suggest that you visit a Samsung service center to have your phone checked out 🤞