feat: Provide details field when throwing Token ownership error

This commit is contained in:
Joachim Van Herwegen
2021-08-27 11:44:14 +02:00
parent cc1c3d9223
commit e31cd38bc5
2 changed files with 6 additions and 2 deletions

View File

@@ -91,6 +91,7 @@ export class TokenOwnershipValidator extends OwnershipValidator {
'to prove it belongs to you.',
'You can remove this triple again after validation.',
].join(' ');
throw new BadRequestHttpError(errorMessage);
const details = { quad: `<${webId}> <${SOLID.oidcIssuerRegistrationToken}> "${token}".` };
throw new BadRequestHttpError(errorMessage, { details });
}
}

View File

@@ -58,7 +58,10 @@ describe('A TokenOwnershipValidator', (): void => {
it('errors if no token is stored in the storage.', async(): Promise<void> => {
// Even if the token is in the WebId, it will error since it's not in the storage
mockFetch(tokenString);
await expect(validator.handle({ webId })).rejects.toThrow(tokenString);
await expect(validator.handle({ webId })).rejects.toThrow(expect.objectContaining({
message: expect.stringContaining(tokenString),
details: { quad: tokenString },
}));
expect(fetch).toHaveBeenCalledTimes(0);
});