Closed mjarmoc closed 4 years ago
Thanks for PR, we will review it!
@mjarmoc, great PR! It will be useful to have more debugging info and ability to handle errors. But we have to keep some headers to stay consistent with .NetCore library that we use in production. Headers are:
-x-error
-x-status-code
We use -x
as error marking header. So to keep naming convention, I suggest using names like:
-x-error-message -> -x-error
-x-error-code -> -x-status-code
-x-error-data -> -x-data
-x-error-service -> -x-service
-x-error-host -> -x-host
-x-error-type -> -x-type
Will it be ok?
And DEFAULT_ERROR_CODE
should be deleted because it is no longer in use.
@AlariCode sure thing, I will prepare the amendments during the weekend ;)
@mjarmoc, great, looking forward for it!
@mjarmoc great, I'll add some format and docs and merge it. But I think two types of error will lead us to code duplication. And we have default case in this code if no '-x-type' header exists:
export class RMQErrorHandler {
public static handle(headers: any): any {
switch (headers['-x-type']) {
case ERROR_TYPE.TRANSPORT:
return new RMQTransportError(
headers['-x-error'],
headers['-x-status-code'],
headers['-x-data'],
headers['-x-service'],
headers['-x-host']
);
case ERROR_TYPE.RMQ:
return new RMQError(
headers['-x-error'],
headers['-x-status-code'],
headers['-x-data'],
headers['-x-service'],
headers['-x-host']
);
default:
// ??
}
}
}
May be we can stick with one error class but with additional parameter like -x-type
? Or we need to create 3rd type of error for default. What do you think?
@mjarmoc, I added docs, changed headers, user only one error class with multiple types and add more typing. Tested it and now ready to merge. Thanks for Merge Request!
This PR introduces:
RMQError
for user thrown errors andRMQTransportError
for transportation/client error.payload, host, servicename, code
which makes debugging easier and more accutare.handle
).