@cobuildlab/8base-utils
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -40,1 +40,9 @@ /** | ||
export declare const _validateReferences: (objs: any, errorPrefix: string) => void; | ||
/** | ||
* Parses the GraphQL error to JSON to get its message. | ||
* If a GraphQL message is not found, it will return the error's message instead. | ||
* | ||
* @param {Error} error - The graphql error. | ||
* @returns {string} The error with the parsed message. | ||
*/ | ||
export declare function getMessageFromGraphQLError(error: Error): any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._validateReferences = exports._validateReference = exports._validateFiles = exports._validateFile = exports._validateNullOrUndefinedOrBlank = void 0; | ||
exports.getMessageFromGraphQLError = exports._validateReferences = exports._validateReference = exports._validateFiles = exports._validateFile = exports._validateNullOrUndefinedOrBlank = void 0; | ||
var validation_utils_1 = require("@cobuildlab/validation-utils"); | ||
@@ -73,1 +73,32 @@ var ValidationError_1 = require("./error/ValidationError"); | ||
}; | ||
/** | ||
* Parses the GraphQL error to JSON to get its message. | ||
* If a GraphQL message is not found, it will return the error's message instead. | ||
* | ||
* @param {Error} error - The graphql error. | ||
* @returns {string} The error with the parsed message. | ||
*/ | ||
function getMessageFromGraphQLError(error) { | ||
var message = error.message; | ||
var jsonStartIndex = message.indexOf(' {'); | ||
var jsonEndIndex = message.lastIndexOf('}') + 1; | ||
var jsonBody = message.substring(jsonStartIndex, jsonEndIndex); | ||
var jsonError; | ||
try { | ||
jsonError = JSON.parse(jsonBody); | ||
} | ||
catch (e) { | ||
console.error('getMessageFromGraphQLError Error: ', e); | ||
return message; | ||
} | ||
var jsonMessage = jsonError.message, raw = jsonError.raw; | ||
if (jsonMessage) { | ||
return jsonMessage; | ||
} | ||
if (raw && raw.message) { | ||
return raw.message; | ||
} | ||
// Return original message. | ||
return message; | ||
} | ||
exports.getMessageFromGraphQLError = getMessageFromGraphQLError; |
{ | ||
"name": "@cobuildlab/8base-utils", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "This is package to deal with common scenarios working with 8base platform", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23935
431