Skip to content

Commit

Permalink
fix(keto-client-wrapper): enhance error handling for Axios errors in …
Browse files Browse the repository at this point in the history
…mock controller
  • Loading branch information
getlarge committed Feb 1, 2025
1 parent 7c7ef46 commit ae4aff0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/keto-client-wrapper/test/app.controller.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
Controller,
ForbiddenException,
Get,
Logger,
Param,
UseGuards,
} from '@nestjs/common';
import { isAxiosError } from 'axios';
import { inspect } from 'node:util';

import { OryAuthorizationGuard } from '../src/lib/ory-authorization.guard';
Expand All @@ -16,11 +16,19 @@ import { ExampleService } from './app.service.mock';
const AuthorizationGuard = () =>
OryAuthorizationGuard({
postCheck(result) {
Logger.log('relationTuple', result.results);
Logger.log('isPermitted', result.allowed);
console.warn('evalation results', result.results);
console.warn('isPermitted', result.allowed);
},
unauthorizedFactory(ctx, error) {
console.error(inspect((error as any).error.response, false, null, true));
const axiosError =
typeof error === 'object' &&
error &&
'error' in error &&
isAxiosError(error.error)
? error.error
: null;
if (axiosError)
console.error(inspect(axiosError.cause, false, null, true));
return new ForbiddenException();
},
});
Expand Down

0 comments on commit ae4aff0

Please sign in to comment.