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

Adding GDSCodes #231

Merged
merged 1 commit into from
Sep 23, 2020
Merged

Adding GDSCodes #231

merged 1 commit into from
Sep 23, 2020

Conversation

pomgui
Copy link
Contributor

@pomgui pomgui commented Sep 22, 2020

This PR adds:

  1. gdscode and gdsparams to database errors.
  2. GDSCode.* constants

Background

When database errors happen, sometimes it's necessary to make decisions based on the error type. Until now the only solution was parsing the error message in order to get the error type and additional data (possibly the constraint name, field, table, etc.)

Error message:

{
  message: 'Error: violation of PRIMARY or UNIQUE KEY constraint "INTEG_164" on table "SPEC_TEST", Problematic key value is ("TEST_ID" = 1)'
}

With the GDS codes in the error object, this is much easier task.

Error object:

{
  gdscode: 335544665,
  gdsparams: ["INTEG_164","SPEC_TEST"],
  message: "violation of PRIMARY or UNIQUE KEY constraint \"INTEG_164\" on table \"SPEC_TEST\", Problematic key value is (\"TEST_ID\" = 1)"
}
// Associated constant: GDSCode.UNIQUE_KEY_VIOLATION = 335544665

The reason for these constants are not exported within the main index.js is that they require memory space which only will be used if they're really needed. That's also the reason to return a numeric gdscode instead of a mnemonic string (that could be trivial to get inside the index.js).

@mariuz mariuz merged commit 03fec08 into hgourvest:master Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants