Skip to content

Commit

Permalink
Merge pull request #978 from ckeditor/ck/16746
Browse files Browse the repository at this point in the history
Fix (dev-ci): Improved error handling by checking both error properties for the `triggerCircleBuild()` util. Closes ckeditor/ckeditor5#16746.
  • Loading branch information
pomek authored Jul 18, 2024
2 parents 06a9561 + 3567d4f commit 9af7fb7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/ckeditor5-dev-ci/lib/trigger-circle-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,9 @@ module.exports = async function triggerCircleBuild( options ) {
if ( response.error_message ) {
throw new Error( `CI trigger failed: "${ response.error_message }".` );
}

if ( response.message ) {
throw new Error( `CI trigger failed: "${ response.message }".` );
}
} );
};
28 changes: 27 additions & 1 deletion packages/ckeditor5-dev-ci/tests/trigger-circle-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe( 'lib/triggerCircleBuild', () => {
expect( body.parameters ).to.have.property( 'triggerRepositorySlug', 'ckeditor/ckeditor5' );
} );

it( 'should reject a promise when CircleCI responds with an error', async () => {
it( 'should reject a promise when CircleCI responds with an error containing error_message property', async () => {
stubs.fetch.resolves( {
json: () => Promise.resolve( {
error_message: 'HTTP 404'
Expand All @@ -155,6 +155,32 @@ describe( 'lib/triggerCircleBuild', () => {
};

return triggerCircleBuild( data )
.then( () => {
throw new Error( 'This error should not be thrown!' );
} )
.catch( err => {
expect( err.message ).to.equal( 'CI trigger failed: "HTTP 404".' );
} );
} );

it( 'should reject a promise when CircleCI responds with an error containing message property', async () => {
stubs.fetch.resolves( {
json: () => Promise.resolve( {
message: 'HTTP 404'
} )
} );

const data = {
circleToken: 'circle-token',
commit: 'abcd1234',
branch: 'master',
repositorySlug: 'ckeditor/ckeditor5-dev'
};

return triggerCircleBuild( data )
.then( () => {
throw new Error( 'This error should not be thrown!' );
} )
.catch( err => {
expect( err.message ).to.equal( 'CI trigger failed: "HTTP 404".' );
} );
Expand Down

0 comments on commit 9af7fb7

Please sign in to comment.