mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Add better support for non-native errors
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import assert from 'assert';
|
||||
import { isNativeError } from '../../../util/errors/ErrorUtil';
|
||||
import { createErrorMessage } from '../../../util/errors/ErrorUtil';
|
||||
import { HttpError } from '../../../util/errors/HttpError';
|
||||
import { IdpInteractionError } from '../util/IdpInteractionError';
|
||||
|
||||
@@ -18,10 +18,8 @@ export function throwIdpInteractionError(error: unknown, prefilled: Record<strin
|
||||
}
|
||||
} else if (HttpError.isInstance(error)) {
|
||||
throw new IdpInteractionError(error.statusCode, error.message, prefilled);
|
||||
} else if (isNativeError(error)) {
|
||||
throw new IdpInteractionError(500, error.message, prefilled);
|
||||
} else {
|
||||
throw new IdpInteractionError(500, 'Unknown Error', prefilled);
|
||||
throw new IdpInteractionError(500, createErrorMessage(error), prefilled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { getLoggerFor } from '../../../../logging/LogUtil';
|
||||
import type { HttpHandlerInput } from '../../../../server/HttpHandler';
|
||||
import { HttpHandler } from '../../../../server/HttpHandler';
|
||||
import type { RenderHandler } from '../../../../server/util/RenderHandler';
|
||||
import { isNativeError } from '../../../../util/errors/ErrorUtil';
|
||||
import { createErrorMessage } from '../../../../util/errors/ErrorUtil';
|
||||
import { getFormDataRequestBody } from '../../util/FormDataUtil';
|
||||
import { assertPassword } from '../EmailPasswordUtil';
|
||||
import type { AccountStore } from '../storage/AccountStore';
|
||||
@@ -53,11 +53,10 @@ export class ResetPasswordHandler extends HttpHandler {
|
||||
},
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
const errorMessage: string = isNativeError(err) ? err.message : 'An unknown error occurred';
|
||||
await this.renderHandler.handleSafe({
|
||||
response: input.response,
|
||||
props: {
|
||||
errorMessage,
|
||||
errorMessage: createErrorMessage(err),
|
||||
recordId: prefilledRecordId,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { HttpHandler } from '../../../server/HttpHandler';
|
||||
import { RouterHandler } from '../../../server/util/RouterHandler';
|
||||
import { isNativeError } from '../../../util/errors/ErrorUtil';
|
||||
import { createErrorMessage } from '../../../util/errors/ErrorUtil';
|
||||
import type { InteractionHttpHandlerInput } from '../InteractionHttpHandler';
|
||||
import { IdpInteractionError } from './IdpInteractionError';
|
||||
import type { IdpRenderHandler } from './IdpRenderHandler';
|
||||
@@ -35,9 +35,8 @@ export class IdpRouteController extends RouterHandler {
|
||||
try {
|
||||
await this.handler.handleSafe(input);
|
||||
} catch (err: unknown) {
|
||||
const errorMessage = isNativeError(err) ? err.message : 'An unknown error occurred';
|
||||
const prefilled = IdpInteractionError.isInstance(err) ? err.prefilled : {};
|
||||
await this.render(input, errorMessage, prefilled);
|
||||
await this.render(input, createErrorMessage(err), prefilled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user