* Log detailed GraphQL error information for diagnosing API failures. * Surfaces the errors array, type codes, paths, HTTP status, and optional domain-specific hints. * * @param {Error & { errors?: Array<{ type?: string, message: string, path?: unknown, locations?: unknown }>, request?: unknown,
(error, operation, hints = {})
| 24 | * @param {GraphQLErrorHints} [hints] - Optional domain-specific hint messages |
| 25 | */ |
| 26 | function logGraphQLError(error, operation, hints = {}) { |
| 27 | core.info(`GraphQL error during: ${operation}`); |
| 28 | core.info(`Message: ${getErrorMessage(error)}`); |
| 29 | |
| 30 | const errorList = Array.isArray(error.errors) ? error.errors : []; |
| 31 | const hasInsufficientScopes = errorList.some(e => e?.type === "INSUFFICIENT_SCOPES"); |
| 32 | const hasNotFound = errorList.some(e => e?.type === "NOT_FOUND"); |
| 33 | |
| 34 | if (hasInsufficientScopes && hints.insufficientScopesHint) { |
| 35 | core.info(hints.insufficientScopesHint); |
| 36 | } |
| 37 | |
| 38 | if (hasNotFound && hints.notFoundHint) { |
| 39 | const predicatePasses = !hints.notFoundPredicate || hints.notFoundPredicate(getErrorMessage(error)); |
| 40 | if (predicatePasses) { |
| 41 | core.info(hints.notFoundHint); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if (error.errors) { |
| 46 | core.info(`Errors array (${error.errors.length} error(s)):`); |
| 47 | error.errors.forEach((err, idx) => { |
| 48 | core.info(` [${idx + 1}] ${err.message}`); |
| 49 | if (err.type) core.info(` Type: ${err.type}`); |
| 50 | if (err.path) core.info(` Path: ${JSON.stringify(err.path)}`); |
| 51 | if (err.locations) core.info(` Locations: ${JSON.stringify(err.locations)}`); |
| 52 | }); |
| 53 | } |
| 54 | |
| 55 | if (error.status) core.info(`HTTP status: ${error.status}`); |
| 56 | if (error.request) core.info(`Request: ${JSON.stringify(error.request, null, 2)}`); |
| 57 | if (error.data) core.info(`Response data: ${JSON.stringify(error.data, null, 2)}`); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get file content from GitHub repository using the API |
no test coverage detected