cache types: how do I identify error types? #2442
-
Hello, When building a readthrough cache in a pipeline, is there a way I can distinguish from an error where I get a cache miss vs some other type of error? processor_resources:
- label: get
processors:
- try:
- cache:
resource: my_cache
operator: get
key: MYKEY
- catch: # how do identify what I am catching is no records found or something is wrong with the cache?
- branch:
result_map: root.value = this
processors:
- resource: call_database
- branch:
result_map: root = this.value
processors:
- try:
- cache:
resource: my_cache
operator: add
key: MY_KEY
value: this.value |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey @smousa 👋 You can use a |
Beta Was this translation helpful? Give feedback.
Hey @smousa 👋 You can use a
switch
processor and check the suffix oferror()
, something likecheck: error().has_suffix("key does not exist")
to detect if it was a cache miss or, depending on the cache type, some other error. Benthos will surface connection errors from various caches, but it doesn't attempt to expose generic errors. For example foraws_s3
, you might get something like "operator failed for key 'test': operation error S3: GetObject, resolve auth scheme: resolve endpoint: endpoint rule error, Invalid region: region was not a valid DNS name." or forredis
you might get "operator failed for key 'test': dial tcp [::1]:6397: connect: connection refused". However, I think you only…