Skip to content

Commit adfb74f

Browse files
committed
implement error and unauthorized
1 parent c5260fd commit adfb74f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { v4 as uuidv4 } from 'uuid';
22
import { toJsonObject } from './rds/index.js'
33

4+
class AppSyncUserError extends Error {
5+
constructor(message, errorType, data, errorInfo) {
6+
super(message);
7+
this.name = "AppSyncUserError";
8+
this.errorType = errorType;
9+
this.data = data;
10+
this.errorInfo = errorInfo;
11+
}
12+
}
13+
414
export const dynamodbUtils = {
515
toDynamoDB: function(value) {
616
if (typeof (value) === "number") {
@@ -121,8 +131,23 @@ export const util = {
121131
return uuidv4();
122132
},
123133
appendError: function(message, errorType, data, errorInfo) {
134+
const error = { message, errorType, data, errorInfo }
135+
if( console.appendError ) {
136+
// LocalStack is adding `appendError` to console to allow adding to context.outErrors
137+
console.appendError(error)
138+
} else {
139+
// This will be handled in LocalStack in a side channel by printing to stderr
140+
console.error({ message, errorType, data, errorInfo });
141+
}
142+
},
143+
error: function(message, errorType, data, errorInfo) {
124144
// This will be handled in LocalStack in a side channel by printing to stderr
125145
console.error({ message, errorType, data, errorInfo });
146+
throw new AppSyncUserError(message, errorType, data, errorInfo)
147+
},
148+
unauthorized: function() {
149+
// This will be handled in LocalStack in a side channel by printing to stderr
150+
throw new AppSyncUserError("Unauthorized", "UnauthorizedException")
126151
},
127152
time: {
128153
nowFormatted: function(pattern) {

0 commit comments

Comments
 (0)