|
1 | 1 | import { v4 as uuidv4 } from 'uuid'; |
2 | 2 | import { toJsonObject } from './rds/index.js' |
3 | 3 |
|
| 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 | + |
4 | 14 | export const dynamodbUtils = { |
5 | 15 | toDynamoDB: function(value) { |
6 | 16 | if (typeof (value) === "number") { |
@@ -121,8 +131,23 @@ export const util = { |
121 | 131 | return uuidv4(); |
122 | 132 | }, |
123 | 133 | 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) { |
124 | 144 | // This will be handled in LocalStack in a side channel by printing to stderr |
125 | 145 | 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") |
126 | 151 | }, |
127 | 152 | time: { |
128 | 153 | nowFormatted: function(pattern) { |
|
0 commit comments