jl777 / SuperNET

57 stars 222 forks source link

Use error codes #717

Open lukechilds opened 6 years ago

lukechilds commented 6 years ago

Currently, in the case of an error, mm returns an error property in the JSON with the value set as the error message.

This means theres no way to handle the errors without checking the entire string. And if the string ever changes in the future, all GUIs trying to handle that specific error will break because their string check will fail.

A better solution would be to return unique error codes along with each error.

Something like:

{
  error: 123,
  message: "cant find a deposit that is close enough in size."
}

that way people can easily handle that specific error with:

if (response.error === 123) {
    splitUtxos();
}

instead of needing to do:

if (response.error === "cant find a deposit that is close enough in size.") {
    splitUtxos();
}

They can still access your error messages with response.message or supply their own.

And you can update error messages without breaking any GUIs because everyone should be checking based on the codes.

jl777 commented 6 years ago

we had making better error handling for 2.0 is it critically required to do now? it seems like a lot of work to find all possible errors and change them, in addition to the existing gui that is relying on the error text

lukechilds commented 6 years ago

Related: https://github.com/jl777/SuperNET/issues/594

is it critically required to do now?

No, not critical, just something we ran into and realised our error checks were likely to break in the future if the wording changed. Just wanted to track it here.