Skip to content

Commit

Permalink
separate RSocketError file
Browse files Browse the repository at this point in the history
Signed-off-by: palani <palam.c@gmail.com>
  • Loading branch information
palamccc committed Feb 20, 2024
1 parent abaa663 commit bb1a4d6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
26 changes: 26 additions & 0 deletions packages/rsocket-core/src/RSocketError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @flow
*/

'use strict';

export default class RSocketError extends Error {
+errorCode: number;
constructor(errorCode: number, message: string) {
super(message);
this.errorCode = errorCode;
}
}
14 changes: 5 additions & 9 deletions packages/rsocket-core/src/RSocketMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
ResponderLeaseHandler,
Disposable,
} from './RSocketLease';
import RSocketError from './RSocketError';

type Role = 'CLIENT' | 'SERVER';

Expand Down Expand Up @@ -867,7 +868,10 @@ class RSocketMachineImpl<D, M> implements RSocketMachine<D, M> {
_sendStreamError(streamId: number, err: Error): void {
this._subscriptions.delete(streamId);
this._connection.sendOne({
code: err instanceof RSocketError ? err.errorCode : ERROR_CODES.APPLICATION_ERROR,
code:
err instanceof RSocketError
? err.errorCode
: ERROR_CODES.APPLICATION_ERROR,
flags: 0,
message: err.message,
streamId,
Expand Down Expand Up @@ -943,11 +947,3 @@ function deserializeMetadataPushPayload<D, M>(
metadata: serializers.metadata.deserialize(frame.metadata),
};
}

export class RSocketError extends Error {
+errorCode: number;
constructor(errorCode: number, message: string) {
super(message);
this.errorCode = errorCode;
}
}
4 changes: 4 additions & 0 deletions packages/rsocket-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import RSocketServer from './RSocketServer';

export {RSocketServer};

import RSocketError from './RSocketError';

export {RSocketError};

import RSocketResumableTransport from './RSocketResumableTransport';

export {RSocketResumableTransport};
Expand Down

0 comments on commit bb1a4d6

Please sign in to comment.