bunsane 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/gql/index.ts +10 -1
  2. package/package.json +1 -1
package/gql/index.ts CHANGED
@@ -114,6 +114,15 @@ const maskError = (error: any, message: string): GraphQLError => {
114
114
  }
115
115
  }
116
116
 
117
+ // Pass through known application-level GraphQL error codes
118
+ const isGQLError = (e: any): e is GraphQLError =>
119
+ e instanceof GraphQLError ||
120
+ (e !== null && typeof e === 'object' && 'extensions' in e && 'message' in e && typeof e.message === 'string');
121
+ const knownCodes = ['FORBIDDEN', 'NOT_FOUND', 'BAD_USER_INPUT', 'BAD_REQUEST'];
122
+ if (isGQLError(error) && knownCodes.includes(error.extensions?.code as string)) {
123
+ return error instanceof GraphQLError ? error : new GraphQLError(error.message, { extensions: error.extensions });
124
+ }
125
+
117
126
  if (process.env.NODE_ENV === 'production') {
118
127
  logger.error("GraphQL Error:", error);
119
128
  // Mask sensitive error details in production
@@ -124,7 +133,7 @@ const maskError = (error: any, message: string): GraphQLError => {
124
133
  });
125
134
  }
126
135
  // In development, return the original error
127
- return error instanceof GraphQLError ? error : new GraphQLError(message, { originalError: error });
136
+ return isGQLError(error) ? (error instanceof GraphQLError ? error : new GraphQLError(error.message, { extensions: error.extensions })) : new GraphQLError(message, { originalError: error });
128
137
  };
129
138
 
130
139
  export interface YogaInstanceOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunsane",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "author": {
5
5
  "name": "yaaruu"
6
6
  },