– You could say that Rex the dog, the hero German shepherd who took at least two bullets protecting his 16-year-old master, has a few flaws.

What hero doesn’t?

But when it was all on the line, when Javier Mercado was alone, hiding and terrified in his family’s Des Moines home while intruders forced their way in, Rex did what every nucleotide of his DNA told him to do.

He defended his owner, the boy with whom he’d slept every night since he was a pup just about three years ago.

Police found Rex sitting in a corner of the parents’ bedroom upstairs, “very bloody, quite injured,” said Jan Magnuson of Des Moines animal control. In that same room, Javier had hidden in the closet.

Magnuson is the one who saved the dog’s life, guiding him into a kennel and rushing the bleeding animal to a vet.

Magnuson and Rex were honored by PETA, the People for the Ethical Treatment of Animals. If Rex could read, he could see that he got a “Heroic Dog Award” from the group.

But about those few flaws.

Magnuson knew Rex from previous times she had been called to the residence. “We had multiple complaints,” she said. Rex never bit anyone, she said, but he did run at people “and bark and growl.”

But Magnuson also said Rex is a brave, good dog. The family said that since the complaints, Rex has been leashed.

In the home invasion, Magnuson said, “He was protecting his home and his family. I am thrilled that he survived. To be honest, when I first saw him, I didn’t think he’d make it.”

Javier is the son of Julia Cadena, an interpreter at a health clinic, and Francisco Mercado, a crane operator. He has two older brothers who also live at home, one in community college, the other a barber.

Most weekdays, Javier is by himself at home. He’s in 11th grade and takes online classes.

His mom said that she read that German shepherds were good pets for kids with attention deficit hyperactivity disorder. “Javier has ADHD. We wanted to get a dog that was at the same energy level,” she said.

Javier was feeding Rex and a friend’s Pomeranian one day last month when he said he “heard a really loud banging on the door.” He texted one of the brothers, “Victor, is that you knocking on the door?”

“I’m at the gym,” was the answer.

Javier looked out one of the upstairs windows. He saw a guy standing at the door. He saw a Dodge Charger.

He texted his mom:

“Ma.”

“Please wya” (shorthand for “where’re you at?”)

“Mom.”

“Come home now.”

“Mom.”

“Please.”

“Mom.”

“Mom.”

“Mom.”

“Mom.”

He texted his dad:

“Pa wya.”

“Come home now.”

“Please.”

Cadena said she was at work and heard the pings on her phone, but thought it was like other times, her son being hungry and wanting Mom to send him some food.

His dad called back, but Javier was on the line with 911 and kept declining his dad’s calls.

By then Javier had seen the first guy and another man go around to the back of the house.

“I heard the sliding door just shatter,” Javier said. “I grabbed the closest thing to me. A screwdriver, a little thing, about 8 inches long.”

He hid in the walk-in closet.

The family had moved to the four-bedroom rental house only seven months earlier. Javier struggled to remember the exact address for the 911 dispatcher. “She finally figured it out,” Javier said.

He could hear Rex barking at the men (the Pomeranian made himself scarce).

Javier could hear the robbers break things. He could hear them kicking down doors inside the house even though they weren’t locked. Later the family would find mattresses that had been stabbed and ripped.

Javier heard one of the guys yell about 77-pound Rex, “Get the dog! The dog bit me!”

Javier could hear Rex run upstairs to the bedroom in which he was hiding. The door to the bedroom was open.

Javier heard four gunshots. Either two or three of the .22 caliber bullets hit Rex. One bullet went through his neck; he also was hit in the rear left leg, breaking it and requiring a surgical pin and screw, and the right front leg, perhaps by the same bullet.

“He cried every time he got hit,” Javier said.

He could hear police sirens. The robbers fled.

Javier had been on the phone to 911 for 53 minutes by the time it was all over.

Des Moines Police Commander Doug Jenkins said they “hope to have a resolution soon” to the case.

Meanwhile, the family has moved out of the house.

Javier is now seeing a psychologist to talk about all that happened. Even Rex has a pet psychologist, as he is jittery when seeing strangers. He wears a cone-shaped collar to prevent him from pulling at 17 staples from the operation.

The prognosis for Rex is good, Cadena said, even though his neck has bullet fragments that couldn’t be extracted.

Javier was asked if Rex took the bullets because the dog felt love for his owner. “Yeah, he did,” he answered.