How to use the node-opcua-status-code.StatusCodes.BadInternalError function in node-opcua-status-code

To help you get started, we’ve selected a few node-opcua-status-code examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-server / source / base_server.ts View on Github external
/* istanbul ignore if */
            const errMessage1 = "EXCEPTION CAUGHT WHILE PROCESSING REQUEST !! " + request.schema.name;
            console.log(chalk.red.bold(errMessage1));

            console.log(request.toString());

            display_trace_from_this_projet_only(err);

            let additional_messages = [];
            additional_messages.push("EXCEPTION CAUGHT WHILE PROCESSING REQUEST !!! " + request.schema.name);
            additional_messages.push(err.message);
            if (err.stack) {
                additional_messages = additional_messages.concat(err.stack.split("\n"));
            }

            response = makeServiceFault(StatusCodes.BadInternalError, additional_messages);

            channel.send_response("MSG", response, message, emptyCallback);
        }
    }
github node-opcua / node-opcua / packages / node-opcua-server / src / server_engine.js View on Github external
//    invalid attributes : BadNodeAttributesInvalid
        //    invalid range      : BadIndexRangeInvalid
        try {
            dataValue = obj.readAttribute(context, attributeId, indexRange, dataEncoding);
            assert(dataValue.statusCode instanceof StatusCode);
            if(!dataValue.isValid()) {
                console.log("Invalid value for node ",obj.nodeId.toString(),obj.browseName.toString());
            }

        }
        catch (err) {
            console.log(" Internal error reading  NodeId       ", obj.nodeId.toString());
            console.log("                         AttributeId  ", attributeId.toString());
            console.log("                        ", err.message);
            console.log("                        ", err.stack);
            return new DataValue({statusCode: StatusCodes.BadInternalError});
        }

        //Xx console.log(dataValue.toString());

        dataValue = apply_timestamps(dataValue, timestampsToReturn, attributeId);

        return dataValue;
    }
};
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
sendInitialValues: boolean): TransferResult {

    assert(session instanceof ServerSession);
    assert(_.isNumber(subscriptionId));
    assert(_.isBoolean(sendInitialValues));

    if (subscriptionId <= 0) {
      return new TransferResult({ statusCode: StatusCodes.BadSubscriptionIdInvalid });
    }

    const subscription = this.findSubscription(subscriptionId);
    if (!subscription) {
      return new TransferResult({ statusCode: StatusCodes.BadSubscriptionIdInvalid });
    }
    if (!subscription.$session) {
      return new TransferResult({ statusCode: StatusCodes.BadInternalError });
    }

    // update diagnostics 
    subscription.subscriptionDiagnostics.transferRequestCount++;

    // now check that new session has sufficient right
    // if (session.authenticationToken.toString() !== subscription.authenticationToken.toString()) {
    //     console.log("ServerEngine#transferSubscription => BadUserAccessDenied");
    //     return new TransferResult({ statusCode: StatusCodes.BadUserAccessDenied });
    // }
    if (session.publishEngine === subscription.publishEngine) {
      // subscription is already in this session !!
      return new TransferResult({ statusCode: StatusCodes.BadNothingToDo });
    }
    if (session === subscription.$session) {
      // subscription is already in this session !!
github node-opcua / node-opcua / packages / node-opcua-address-space / src / ua_method.js View on Github external
// Todo : ...
            const outputArgsDef = self.getOutputArguments();

            //xx assert(outputArgsDef.length === callMethodResponse.outputArguments.length,
            //xx     "_asyncExecutionFunction did not provide the expected number of output arguments");
            // to be continued ...


            callback(err, callMethodResponse);

        });

    } catch(err){
        console.log("ERR in method  handler".red,err.message);
        console.error(err.stack);
        const callMethodResponse = { statusCode: StatusCodes.BadInternalError};
        callback(err, callMethodResponse);

    }

};
github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / server / server_secure_channel_layer.ts View on Github external
this._process_certificates(message, (err: Error | null, statusCode?: StatusCode) => {

            if (err) {
                description = "Internal Error " + err.message;
                return this._send_error(StatusCodes.BadInternalError, description, message, callback);
            }
            if (!statusCode) {
                assert(false);
            }
            if (statusCode !== StatusCodes.Good) {
                const description = "Sender Certificate Error";
                console.log(chalk.cyan(description), chalk.bgRed.yellow(statusCode!.toString()));
                // OPCUA specification v1.02 part 6 page 42 $6.7.4
                // If an error occurs after the  Server  has verified  Message  security  it  shall  return a  ServiceFault  instead
                // of a OpenSecureChannel  response. The  ServiceFault  Message  is described in  Part  4,   7.28.
                return this._send_error(statusCode!, "", message, callback);
            }

            this._handle_OpenSecureChannelRequest(message, callback);
        });
    }
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
this: ServerEngine,
  inputArguments: any,
  context: SessionContext,
  callback: any
) {

  const engine = this; // ServerEngine

  assert(_.isArray(inputArguments));
  assert(_.isFunction(callback));

  assert(context.hasOwnProperty("session"), " expecting a session id in the context object");

  const session = context.session as ServerSession;
  if (!session) {
    return callback(null, { statusCode: StatusCodes.BadInternalError });
  }

  const subscriptionId = inputArguments[0].value;
  const subscription = session.getSubscription(subscriptionId);
  if (!subscription) {
    // subscription may belongs to a different session  that ours
    if (engine.findSubscription(subscriptionId)) {
      // if yes, then access to  Subscription data should be denied
      return callback(null, { statusCode: StatusCodes.BadUserAccessDenied });
    }

    return callback(null, { statusCode: StatusCodes.BadSubscriptionIdInvalid });
  }
  const result = subscription.getMonitoredItems();
  assert(result.statusCode);
  assert(_.isArray(result.serverHandles));
github node-opcua / node-opcua / packages / node-opcua-server / src / opcua_server.js View on Github external
server.isUserAuthorized(channel, session, request.userIdentityToken, function (err, authorized) {

        if (err) {
            return rejectConnection(StatusCodes.BadInternalError);
        }

        if (!authorized) {
            return rejectConnection(StatusCodes.BadUserAccessDenied);
        } else {
            // extract : OPC UA part 4 - 5.6.3
            // Once used, a serverNonce cannot be used again. For that reason, the Server returns a new
            // serverNonce each time the ActivateSession Service is called.
            session.nonce = server.makeServerNonce();

            session.status = "active";

            response = new ActivateSessionResponse({serverNonce: session.nonce});
            channel.send_response("MSG", response, message);

            const userIdentityTokenPasswordRemoved = function (userIdentityToken) {
github node-opcua / node-opcua / packages / node-opcua-server / src / opcua_server.js View on Github external
}, function (err) {
            /* istanbul ignore next */
            if (err) {
                channel.send_error_and_abort(StatusCodes.BadInternalError, err.message, "", function () {
                });
            }
        });
    });
github node-opcua / node-opcua / packages / node-opcua-client / source / alarms_and_conditions / client_alarm_tools_acknowledge_all_conditions.ts View on Github external
export async function acknowledgeCondition(session: ClientSession, eventStuff: EventStuff, comment: string): Promise {

    try {
        const conditionId = eventStuff.conditionId.value;
        const eventId = eventStuff.eventId.value;
        return await session.acknowledgeCondition(conditionId, eventId, comment);
    } catch (err) {
        errorLog("Acknwoledding alarm has failed !", err);
        return StatusCodes.BadInternalError;
    }
}
export async function confirmCondition(session: ClientSession, eventStuff: EventStuff, comment: string): Promise {
github node-opcua / node-opcua / packages / node-opcua-server / source / server_engine.ts View on Github external
public deleteOrphanSubscription(subscription: Subscription): StatusCode {
    if (!this._orphanPublishEngine) {
      return StatusCodes.BadInternalError;
    }
    assert(this.findSubscription(subscription.id));

    const c = this._orphanPublishEngine.subscriptionCount;
    subscription.terminate();
    subscription.dispose();
    assert(this._orphanPublishEngine.subscriptionCount === c - 1);
    return StatusCodes.Good;
  }