Errors handling

During wampy instance lifetime there can be many cases when error happens: some made by developer mistake, some are bound to WAMP protocol violation, some came from other peers. Errors that can be caught by wampy instance itself are stored in opStatus.error, while others are just thrown.

This allows, for example, convenient handling of different types of errors:

import {Wampy, Errors} from 'wampy';
const wampy = new Wampy('/ws/', { realm: 'AppRealm' });

try {
    await wampy.call('start.migration');
    console.log('RPC successfully called');
} catch (e) {
    console.log('Error happened!');
    if (e instanceof Errors.UriError) {
        // statements to handle UriError exceptions
    } else if (e instanceof Errors.InvalidParamError) {
        // statements to handle InvalidParamError exceptions
    } else if (e instanceof Errors.NoSerializerAvailableError) {
        // statements to handle NoSerializerAvailableError exceptions
    } else {
        // statements to handle any unspecified exceptions
    }
}

Wampy package exposes next Errors classes:

  • UriError

  • NoBrokerError

  • NoCallbackError

  • InvalidParamError

  • NoSerializerAvailableError

  • NonExistUnsubscribeError

  • NoDealerError

  • RPCAlreadyRegisteredError

  • NonExistRPCUnregistrationError

  • NonExistRPCInvocationError

  • NonExistRPCReqIdError

  • NoRealmError

  • NoWsOrUrlError

  • NoCRACallbackOrIdError

  • ChallengeExceptionError

  • PPTNotSupportedError

  • PPTInvalidSchemeError

  • PPTSerializerInvalidError

  • PPTSerializationError

  • ProtocolViolationError

  • AbortError

  • WampError

  • SubscribeError

  • UnsubscribeError

  • PublishError

  • RegisterError

  • UnregisterError

  • CallError

  • WebsocketError

For errors attributes look at src/errors.js file.

Last updated