This repository has been archived by the owner on Sep 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b7a42f
commit c95b250
Showing
14 changed files
with
109 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/implementationsWrappers/callsFinalizers/bidirectionalStreamingCall.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { streamToRx } = require("rxjs-stream"); | ||
|
||
module.exports = function(handler) { | ||
return async call => { | ||
call.source = streamToRx(call); | ||
await handler(call); | ||
call.end(); | ||
}; | ||
}; |
8 changes: 8 additions & 0 deletions
8
src/implementationsWrappers/callsFinalizers/ingoingStreamingCall.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { streamToRx } = require("rxjs-stream"); | ||
|
||
module.exports = function(handler) { | ||
return async (call, callback) => { | ||
call.source = streamToRx(call); | ||
callback(null, await handler(call)); | ||
}; | ||
}; |
6 changes: 6 additions & 0 deletions
6
src/implementationsWrappers/callsFinalizers/outgoingStreamingCall.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = function(handler) { | ||
return async call => { | ||
await handler(call); | ||
call.end(); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function(handler) { | ||
return async (call, callback) => callback(null, await handler(call)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const grpc = require("grpc"); | ||
const GRPCError = require("grpc-error"); | ||
|
||
/** | ||
* @param {Error} error | ||
* @returns {GRPCError} | ||
*/ | ||
const createGrpcError = error => { | ||
const stackTrace = error.stack.replace(/\r?\n|\r/g, " "); | ||
return /^[ -~]*$/.test(stackTrace) | ||
? new GRPCError(error, grpc.status.INTERNAL, { stackTrace }) | ||
: new GRPCError(error, grpc.status.INTERNAL); | ||
}; | ||
|
||
module.exports = function(methodDefinition, handler, logger) { | ||
return async (call, callback) => { | ||
try { | ||
await handler(call, callback); | ||
} catch (error) { | ||
let grpcError = error; | ||
if (error instanceof GRPCError === false && error.constructor.toString() !== GRPCError.toString()) { | ||
logger.error("Unhandled exception has occurred in method {methodName}", { | ||
error, | ||
methodName: methodDefinition.path | ||
}); | ||
grpcError = createGrpcError(error); | ||
} | ||
|
||
if (callback) callback(grpcError); | ||
else call.emit("error", grpcError); | ||
} | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const processingContext = require("processing-context"); | ||
|
||
module.exports = async function(call, methodDefinition, callback, next) { | ||
module.exports = async function(call, methodDefinition, next) { | ||
processingContext.create(); | ||
await next(call, callback); | ||
return next(call); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.