I thought I'd add my take on this since I'm only interested in the first integer I boiled it down to this:
let errorStringWithNumbers = "error: 404 (not found)";
let errorNumber = parseInt(errorStringWithNumbers.toString().match(/\d+/g)[0]);
.toString()
is added only if you get the "string" from an fetch error. If not, then you can remove it from the line.