errors.QueryResultError()

new QueryResultError()

This error is specified as the rejection reason for all result-specific methods when the result doesn't match the expectation, i.e. when a query result doesn't match its Query Result Mask - the value of queryResult.

The error applies to the result from the following methods: none, one, oneOrNone and many.

Supported errors:

  • No return data was expected., method none
  • No data returned from the query., methods one and many
  • Multiple rows were not expected., methods one and oneOrNone

Like any other error, this one is notified with through the global event error.

The type is available from the errors namespace.

Properties:
Name Type Description
name string

Standard Error property - error type name = QueryResultError.

message string

Standard Error property - the error message.

stack string

Standard Error property - the stack trace.

result object

The original Result object that was received.

received number

Total number of rows received. It is simply the value of result.rows.length.

code number

Error code - queryResultErrorCode value.

query string

Query that was executed.

Normally, it is the query already formatted with values, if there were any. But if you are using initialization option pgFormatting, then the query string is before formatting.

values *

Values passed in as query parameters. Available only when initialization option pgFormatting is used. Otherwise, the values are within the pre-formatted query string.

Source:
See:
Example
const QueryResultError = pgp.errors.QueryResultError;
const qrec = pgp.errors.queryResultErrorCode;

const initOptions = {

  // pg-promise initialization options...

  error(err, e) {
      if (err instanceof QueryResultError) {
          // A query returned unexpected number of records, and thus rejected;
          
          // we can check the error code, if we want specifics:
          if(err.code === qrec.noData) {
              // expected some data, but received none;
          }

          // If you write QueryResultError into the console,
          // you will get a nicely formatted output.

          console.log(err);
          
          // See also: err, e.query, e.params, etc.
      }
  }
};

Extends

Methods

toString(levelopt) → {string}

Creates a well-formatted multi-line string that represents the error.

It is called automatically when writing the object into the console.

Parameters:
Name Type Attributes Default Description
level number <optional>
0

Nested output level, to provide visual offset.

Source:
Returns:
Type
string