Error response enhancements, CoreID auth client backend
This commit is contained in:
@@ -72,9 +72,12 @@ export class ErrorResponseFactory extends ResponseFactory {
|
||||
}
|
||||
}
|
||||
|
||||
const suggestion = this.getSuggestion()
|
||||
|
||||
let str = `
|
||||
<b>Sorry, an unexpected error occurred while processing your request.</b>
|
||||
<br>
|
||||
${suggestion ? '<br><b>Suggestion:</b> ' + suggestion + '<br>' : ''}
|
||||
<pre><code>
|
||||
Name: ${thrownError.name}
|
||||
Message: ${thrownError.message}
|
||||
@@ -88,7 +91,7 @@ Stack trace:
|
||||
str += `
|
||||
<pre><code>
|
||||
Context:
|
||||
${Object.keys(context).map(key => ` - ${key} : ${context[key]}`)
|
||||
${Object.keys(context).map(key => ` - ${key} : ${JSON.stringify(context[key]).replace(/\n/g, '<br>')}`)
|
||||
.join('\n')}
|
||||
</code></pre>
|
||||
`
|
||||
@@ -100,4 +103,12 @@ ${Object.keys(context).map(key => ` - ${key} : ${context[key]}`)
|
||||
protected buildJSON(thrownError: Error): string {
|
||||
return JSON.stringify(api.error(thrownError))
|
||||
}
|
||||
|
||||
protected getSuggestion(): string {
|
||||
if ( this.thrownError.message.startsWith('No such dependency is registered with this container: class SecurityContext') ) {
|
||||
return 'It looks like this route relies on the security framework. Is the route you are accessing inside a middleware (e.g. SessionAuthMiddleware)?'
|
||||
}
|
||||
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import {Request} from '../lifecycle/Request'
|
||||
* Helper function to create a new RedirectResponseFactory to the given destination.
|
||||
* @param destination
|
||||
*/
|
||||
export function redirect(destination: string): RedirectResponseFactory {
|
||||
return new RedirectResponseFactory(destination)
|
||||
export function redirect(destination: string|URL): RedirectResponseFactory {
|
||||
return new RedirectResponseFactory(destination instanceof URL ? destination.toString() : destination)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user