The same question applies to practically all space sondes that leave a near Earth orbit. If one of the Mars rover breaks, you can't call your local service station to send an engineer and get it repaired. Or think of New Horizons that went to Pluto.
Basically, the sondes get designed and tested as much on Earth as possible to withstand all the forces of the launch and the environmental conditions in space (radiation, heating/cooling cycles etc) and by now the engineers have a lot of experience.
A sonde consists of many different components and some are redundant (i.e. there are several systems that can take over each other's function), so when something fails, the sonde is still usable with possibly limited functionality. It's not like a car breakdown where you're really stuck in the middle of nowhere and can't move until it's repaired.
For space sondes, there are certain ways of "repairing" by uploading new software that e.g. disables malfunctioning instruments or modifies their function.
In the past, there are many examples of sondes where certain components failed and the sonde continued to be used, often long beyond the original design life.
An instructive example is the Kepler space telescope. Two of the four reaction wheels failed in 2012; they stabilise the sonde so that it points precisely in the desired direction (this is called "attitude control"), so their failure is a serious problem for a space telescope as it becomes useless if you can't point it to where you want.
So they put it into powersaving mode for a while and designed a new mission using the remaining capabilities, which started 2013 and run for another 5 years until 2019, so this is pretty good for a failure that is almost as bad as you can get. For this second mission, they didn't need any actual "repairs" but uploaded software so it could be stabilisied with the two remaining reaction wheels (by turning it such that the radiation pressure from the sun provided some force). It was more restricted and could only observe certain parts of the sky, but it still delivered a lot of data even the failure.
So for Webb, we hope it works of course, but if something breaks, they will analyse the problem and work around the failed components to continue a useful mission.
A more frequent experience is that sondes have worked perfectly fine for the planned design life, and still continued to work afterwards with perhaps some components failing one after another many years after the original design life. So the missions get extended, redesigned and modified to get as much out of the instruments as long as they are somewhat functional. I guess the record are the Voyager and Pioneer sondes that were designed for 3 or 4 years but worked (at least) ten times as long.