karrioapi / karrio

Programmable Shipping API (self-hosted)
https://karrio.io
Apache License 2.0
542 stars 99 forks source link

feat: add error level flag #657

Open jacobshilitz opened 2 months ago

jacobshilitz commented 2 months ago

Is your feature request related to a problem? Please describe. Some carriers return notes and warnings which are not errors, but they can be useful. for example, FedEx we disabled the "note" type messages because it was not an error, see commit https://github.com/karrioapi/karrio/commit/4d2a07b6c3c1a267783e0275260f523882b149ef.

Describe the solution you'd like Add a level to message object that indicates whether it's an error or just a notice. and add support for all the carriers

I thought it can maybe also be a setting in the user or in the API in each call, what errors should be suppressed

jacobshilitz commented 2 months ago

@danh91 can you give some input on how you would like this to be implemented?

danh91 commented 2 months ago

Hi @jacobshilitz,

Yes, adding an optional level field to the Message type is the way to go.

https://github.com/karrioapi/karrio/blob/330a6b9a9c337bb25391c34a6322ee04c72dd175/modules/sdk/karrio/core/models.py#L239-L246

So that every carrier integration can adopt it progressively on there error parsing functions.

e.g. fedex

pass the level to the Message type

https://github.com/karrioapi/karrio/blob/330a6b9a9c337bb25391c34a6322ee04c72dd175/modules/connectors/fedex/karrio/providers/fedex/error.py#L48-L62

The only thing is we need to standardize the levels with an enum like

class MessageLevelEnum(Enum):
   note
   warning
   error

The enum can be in the sdk/karrio/core/units.py file.

These are the ones I have seen in general. What do you think?