Reader small image

You're reading from  Hands-On Microservices with Django

Product typeBook
Published inMay 2024
PublisherPackt
ISBN-139781835468524
Edition1st Edition
Right arrow
Author (1)
Tieme Woldman
Tieme Woldman
author image
Tieme Woldman

Tieme Woldman works as a freelance Python developer and technical writer. As a Python developer, he builds web and data engineering applications with Django and Python data transformation packages such as pandas. As a technical writer, he has written software and user documentation for software companies such as Instruqt, Noldus Information Technology, and Rulecube. Tieme lives in the Netherlands, has a bachelor's degree in computer science, and holds several (technical) writing certifications.
Read more about Tieme Woldman

Right arrow

Error handling

Error handling is essential for developing robust and resilient microservices.

Depending on the robustness requirements for your microservice application, error handling can vary from simply catching and logging errors to extensive retry mechanisms or gentle degradation.

Catching and logging errors should be the minimum for our microservices, so we’ll look specifically at that.

Catch and log errors

Python has the try...except block structure to catch errors and unexpected events and it’s good practice to incorporate this into your workers to make them robust and resilient. Moreover, if we log errors from try...except blocks, we combine logging and error handling, which further optimizes microservice execution.

For example, we can extend send_email_task to handle errors like this:

1 import logging
2 from smtplib import SMTPException
   ...
9 logging.basicConfig(filename="workers_logs.txt",
    ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Hands-On Microservices with Django
Published in: May 2024Publisher: PacktISBN-13: 9781835468524

Author (1)

author image
Tieme Woldman

Tieme Woldman works as a freelance Python developer and technical writer. As a Python developer, he builds web and data engineering applications with Django and Python data transformation packages such as pandas. As a technical writer, he has written software and user documentation for software companies such as Instruqt, Noldus Information Technology, and Rulecube. Tieme lives in the Netherlands, has a bachelor's degree in computer science, and holds several (technical) writing certifications.
Read more about Tieme Woldman