Enhancing SOAR Queries: Improved Error Handling and Support for Distance-Based Filtering

Improved Error Handling and Support for Distance-Based Filtering

Introduction

Over the past few weeks, I’ve been working on addressing and enhancing certain functionalities within the sunpy-soar package. This post delves into the two main improvements I’ve implemented: better error handling for server downtime and the introduction of support for distance-based query filtering.

Improved Error Handling for Server Downtime

Previously, when the SOAR server was down, a generic JSONDecodeError would be raised. This was less than ideal as it did not provide a clear indication of what the actual issue was. To improve this, I worked on implementing a more descriptive error message that would be raised in such scenarios.

r = requests.get(f"{tap_endpoint}/sync", params=payload)
try:
response_json = r.json()
except JSONDecodeError:
msg = "Server returned an invalid JSON response. The SOAR server may be down or not functioning correctly."
raise RuntimeError(msg)

With this change, users will now see a RuntimeError with a clear message indicating that the server may be down or not functioning correctly, which makes troubleshooting much easier.

Implementing Support for Different REQUEST Types

After resolving the error handling issue, I moved on to implementing support for different REQUEST types. Sunpy-soar initially only supported the doQuery REQUEST type. However, there was a need to expand this to support the doQueryFilteredByDistance REQUEST type as well.

What is doQueryFilteredByDistance?

The doQueryFilteredByDistance REQUEST type allows for filtering the query results based on a specified distance range. The main change here is setting the REQUEST parameter to doQueryFilteredByDistance and appending &DISTANCE(distancemin,distancemax) to the query.

Example Query:

SELECT * FROM soar.v_sc_data_item WHERE instrument='MAG' AND level='LL02'

With Distance Filtering:

SELECT * FROM soar.v_sc_data_item WHERE instrument='MAG' AND level='LL02' AND DISTANCE(0.28,0.49)

Conclusion

These enhancements significantly improve the functionality and user experience of the sunpy-soar package. The improved error handling provides clearer feedback to users when the SOAR server is down, and the support for doQueryFilteredByDistance allows for more refined queries based on distance, opening up new possibilities for data analysis.