diff --git a/src/main.ts b/src/main.ts index 752b8d0f..529e540b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import { getInput, info, setFailed, warning } from '@actions/core'; import { getOctokit } from '@actions/github'; +import { RequestError } from '@octokit/request-error'; import { CommitStatusState, getCommitHash, @@ -20,6 +21,10 @@ interface Inputs { context?: string; } +interface ValidationFailedError { + errors: object | string; +} + function getInputs(): Inputs { const token = getInput('token', { required: true }); const state = validateCommitStatusState(getInput('status', { required: true })); @@ -66,7 +71,18 @@ async function run(): Promise { context: inputs.context, }); } catch (error) { - setFailed((error as Error).message); + let foundMoreElaborateError = false; + const reqError = error as RequestError; + if (reqError.response !== undefined) { + const errorData = reqError.response.data as ValidationFailedError; + if (typeof errorData.errors === 'string') { + foundMoreElaborateError = true; + setFailed(errorData.errors); + } + } + if (!foundMoreElaborateError) { + setFailed((error as Error).message); + } } }