Pilgrim's Progress deals with this. Hopeful and Christian travel to the Celestial City and under Christian's counsel they deviate from the path and encounter the limits of Doubting Castle. Here they are captured by Giant Despair and "put them into his castle, into a very dark dungeon, nasty and stinking to the spirits of these two men. [Ps. 88:18]". Under the counsel of his wife, Diffidence (or Distrust in another version) they are beaten by him and left almost dead. "So all that day they spent the time in nothing but sighs and bitter lamentations."
After this, Giant Despair comes back and tells them that they will likely not leave and encourages them to take their lives (read their discussion on suicide). Christian becomes more discouraged and says:
For my part I know not whether is best, to live thus, or to die out of hand. "My soul chooseth strangling rather than life", and the grave is more easy for me than this dungeon. [Job 7:15] Shall we be ruled by the Giant?
Hopeful encourages him and makes him feel better but they are still in a "sad and doleful condition."
When Giant despair comes back to see them he becomes angry that they have not followed his advice. That night after consulting with his wife, she encourages him to show them the skulls of those he has killed and torn to pieces and warn them that they will suffer the same fate. The Giant Despair does so and beats them again and yet he cannot break them. That night Hopeful and Christian spend the night in prayer. It is after this that Christians says:
What a fool, quoth he, am I, thus to lie in a stinking Dungeon, when I may as well walk at liberty. I have a Key in my bosom called Promise, that will, I am persuaded, open any Lock in Doubting Castle.
And with the Key Christian opens the door and gate of the Castle and escape the grip of Giant
This part teaches us a lot about discouragement or despair. It can have a strong hold in our lives. It takes away all of our physical, mental and spiritual strength. It attempts to destroy us by making us feel useless and worthless by consistently "beating" us to the ground. The antidote is key of promise. It is the promise that we are secured in Christ:
What shall we then say to these things? If God be for us, who can be against us? He that spared not his own Son, but delivered him up for us all, how shall he not with him also freely give us all things? Who shall lay any thing to the charge of God's elect? It is God that justifieth. Who is he that condemneth? It is Christ that died, yea rather, that is risen again, who is even at the right hand of God, who also maketh intercession for us. Who shall separate us from the love of Christ? shall tribulation, or distress, or persecution, or famine, or nakedness, or peril, or sword? As it is written, For thy sake we are killed all the day long; we are accounted as sheep for the slaughter.
Nay, in all these things we are more than conquerors through him that loved us. For I am persuaded, that neither death, nor life, nor angels, nor principalities, nor powers, nor things present, nor things to come, Nor height, nor depth, nor any other creature, shall be able to separate us from the love of God, which is in Christ Jesus our Lord. - Romans 8:31-39
There are also many other promises given to us that we can claim in the midst of despair. The book of Psalms is also a good book to read during these times (see for example Psalm 40 and here for more verses).
Read more about how to deal with depression or despair here and here.