Usually, cleaning the charge port out with some isopropyl alcohol and letting it air-dry will fix this. Sometimes there is a bit of moisture stuck in lint inside the charge port, and the phone can detect it. You can also try cleaning the charger connector itself in case it has any moisture in it.
The isopropyl alcohol (the gusher the percentage the better, recommend is 99%) will remove any water that’s in there, just make sure it’s dry before you try charging again.
Be careful when you’re cleaning the charge port. The Micro-USB port is very delicate and you don’t want to damage any pins while cleaning. A toothpick could work, and you could try some compressed air/electronics cleaner if you’re not comfortable sticking something into the charge port.
If this all fails, you could attempt to replace the charge port itself. This would involve knowledge of soldering g though, since I think the charge board is attached to the screen on the S7 Edge.
Hope this helps. 😊