mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
revert back to throwing AuthError, and handle that outside the controller instead
This commit is contained in:
parent
0e43286435
commit
39e6432b05
|
@ -8,6 +8,7 @@ import type { ZodClass } from 'zod-class';
|
||||||
|
|
||||||
import { AuthService } from '@/auth/auth.service';
|
import { AuthService } from '@/auth/auth.service';
|
||||||
import { inProduction, RESPONSE_ERROR_MESSAGES } from '@/constants';
|
import { inProduction, RESPONSE_ERROR_MESSAGES } from '@/constants';
|
||||||
|
import { ResponseError } from '@/errors/response-errors/abstract/response.error';
|
||||||
import { UnauthenticatedError } from '@/errors/response-errors/unauthenticated.error';
|
import { UnauthenticatedError } from '@/errors/response-errors/unauthenticated.error';
|
||||||
import type { BooleanLicenseFeature } from '@/interfaces';
|
import type { BooleanLicenseFeature } from '@/interfaces';
|
||||||
import { License } from '@/license';
|
import { License } from '@/license';
|
||||||
|
@ -102,7 +103,15 @@ export class ControllerRegistry {
|
||||||
}
|
}
|
||||||
} else throw new ApplicationError('Unknown arg type: ' + arg.type);
|
} else throw new ApplicationError('Unknown arg type: ' + arg.type);
|
||||||
}
|
}
|
||||||
return await controller[handlerName](...args);
|
try {
|
||||||
|
return await controller[handlerName](...args);
|
||||||
|
} catch (error) {
|
||||||
|
if (route.usesTemplates && error instanceof ResponseError) {
|
||||||
|
res.writeHead(error.httpStatusCode, { 'Content-Type': 'text/plain' });
|
||||||
|
return res.end(error.message);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
router[route.method](
|
router[route.method](
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { validate } from 'class-validator';
|
import { validate } from 'class-validator';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import querystring from 'querystring';
|
import querystring from 'querystring';
|
||||||
import type { PostBindingContext } from 'samlify/types/src/entity';
|
|
||||||
import url from 'url';
|
import url from 'url';
|
||||||
|
|
||||||
import { AuthService } from '@/auth/auth.service';
|
import { AuthService } from '@/auth/auth.service';
|
||||||
|
@ -10,7 +9,6 @@ import { AuthError } from '@/errors/response-errors/auth.error';
|
||||||
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
|
||||||
import { EventService } from '@/events/event.service';
|
import { EventService } from '@/events/event.service';
|
||||||
import { AuthenticatedRequest } from '@/requests';
|
import { AuthenticatedRequest } from '@/requests';
|
||||||
import { sendErrorResponse } from '@/response-helper';
|
|
||||||
import { UrlService } from '@/services/url.service';
|
import { UrlService } from '@/services/url.service';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -149,8 +147,7 @@ export class SamlController {
|
||||||
userEmail: loginResult.attributes.email ?? 'unknown',
|
userEmail: loginResult.attributes.email ?? 'unknown',
|
||||||
authenticationMethod: 'saml',
|
authenticationMethod: 'saml',
|
||||||
});
|
});
|
||||||
// Need to manually send the error response since we're using templates
|
throw new AuthError('SAML Authentication failed');
|
||||||
return sendErrorResponse(res, new AuthError('SAML Authentication failed'));
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (isConnectionTestRequest(req)) {
|
if (isConnectionTestRequest(req)) {
|
||||||
return res.render('sso/saml-connection-test-failed', { message: (error as Error).message });
|
return res.render('sso/saml-connection-test-failed', { message: (error as Error).message });
|
||||||
|
@ -159,11 +156,7 @@ export class SamlController {
|
||||||
userEmail: 'unknown',
|
userEmail: 'unknown',
|
||||||
authenticationMethod: 'saml',
|
authenticationMethod: 'saml',
|
||||||
});
|
});
|
||||||
// Need to manually send the error response since we're using templates
|
throw new AuthError('SAML Authentication failed: ' + (error as Error).message);
|
||||||
return sendErrorResponse(
|
|
||||||
res,
|
|
||||||
new AuthError('SAML Authentication failed: ' + (error as Error).message),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue