Matthew 15:22-28 (KJV) read "And, behold, a woman of Canaan came out of the same coasts, and cried unto him, saying, Have mercy on me, O Lord, thou Son of David; my daughter is grievously vexed with a devil. But he answered her not a word. And his disciples came and besought him, saying, Send her away; for she crieth after us. But he answered and said, I am not sent but unto the lost sheep of the house of Israel. Then came she and worshipped him, saying, Lord, help me. But he answered and said, It is not meet to take the children's bread, and to cast it to dogs. And she said, Truth, Lord: yet the dogs eat of the crumbs which fall from their masters' table. Then Jesus answered and said unto her, O woman, great is thy faith: be it unto thee even as thou wilt. And her daughter was made whole from that very hour."
(https://bible.com/bible/1/mat.15.22-28.KJV)
It does seem harsh that Jesus rejected the Canaanite woman and metaphorised her and Canaanites as dogs. However, if you read the old testament, you'd know that Canaan (the person which land of Canaan was derived from) was cursed because of his father Ham sinned by looking upon Noah's naked body. (See Genesis 9:20-27, cf. Leviticus 20:11)
Therefore it is safe to say the author deliberately framed it to show that Jesus was using this scenario to demonstrate God's mercy. Though Canaan and Canaanites were cursed (which explains Jesus's refusal and rejection with harsh words), their repentance and submission to God had softened God's heart to allow mercy to be upon them.
It'll be reading too much into the details to say Jesus was racist or Jesus was discriminating against Canaanites, etc. The whole story points to what God is trying to do through Jesus and His ministry -- to bring the Kingdom of God back to earth and reconcile with all God's people. This story in particular reminds us that the sins of our past had been carried forward indefinitely but God put a stop to it by making the ultimate atonement.