Tribler / tribler

Privacy enhanced BitTorrent client with P2P content discovery
https://www.tribler.org
GNU General Public License v3.0
4.86k stars 451 forks source link

Consolidate REST error responses #8263

Closed qstokkink closed 1 week ago

qstokkink commented 1 week ago

We inconsistently use REST error responses.

2 instances:

{
  error: {
    handled: boolean,
    message: string,
  }
}

3 instances:

{
  error: {
    handled: boolean,
    code: string,
    message: string,
  }
}

52 instances:

{
  error: string
}

This is bad because it causes error handling constructions like this:

https://github.com/Tribler/tribler/blob/6213050af39f9d074914e6007d8d5da8fac38c66/src/tribler/ui/src/dialogs/SaveAs.tsx#L156-L163

qstokkink commented 1 week ago

@egbertbouman what do you think of cosolidating this to:

{
  error: {
    handled: boolean,
    message: string,
  }
}

For the errors with a code we would port the code field by including it in the message. For the errors that currently only have an error message we would put them in a {handled=True, message="previously the 'error' message"}.

egbertbouman commented 1 week ago

Sounds good to me 👍

qstokkink commented 1 week ago

Thanks 🙏 I'll give this a go then.