Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileMakerError adds too much abstraction #15

Open
steveWinter opened this issue Nov 19, 2019 · 1 comment
Open

FileMakerError adds too much abstraction #15

steveWinter opened this issue Nov 19, 2019 · 1 comment

Comments

@steveWinter
Copy link

Currently if FileMaker server returns an error an exception of type FileMakerError is raised. The same exception is used for all error types.

The problem that I am finding is that I now have to parse a lengthy text string to determine what the error actually was. In many instances this wouldn't be an issues, since it's likely to be fatal to the program execution and I'd need to log the exception (for example) and then provide some generic error response.

There are however times when you want to catch a specific error and behave differently for those. Immediate use cases I'm dealing with are

  • no records (401)
  • validation failed (503 - 507)

Would it be possible to either raise alternative exceptions for these errors, or expose the error code in the current exception?

@davidhamann
Copy link
Owner

Currently, everything is a FileMakerError, but you can already get the error code directly from the Server.last_error property (returns an int, no need to parse text).

Example:

fms = fmrest.Server(...)
fms.login()
try:
    fms.find(query=[{'name': 'non-existing'}])
except FileMakerError:
    print(fms.last_error) # prints 401

By the way: the last script result is also always accessible through the last_script_result property.

Having separate exceptions (at least for the common cases) might be something to look into though. It probably reads nicer than the generic FileMakerError.

Maybe something like this:

try:
  fms.find(...)
except NoMatch:
  ...

We could subclass FileMakerError and thus keep it backward-compatible for existing implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants