|
|
@ -1,5 +1,6 @@ |
|
|
|
import { CosmosClient } from '@azure/cosmos' |
|
|
|
import { Plugin } from 'fastify' |
|
|
|
import trim from 'lodash/trim' |
|
|
|
import { Server, IncomingMessage, ServerResponse } from 'http' |
|
|
|
|
|
|
|
import { JWT } from '../../lib/crypto' |
|
|
@ -11,7 +12,7 @@ import posts from './posts' |
|
|
|
import uploads from './uploads' |
|
|
|
import users from './users' |
|
|
|
|
|
|
|
import { PluginOptions } from '../../types' |
|
|
|
import { PluginOptions, HttpError } from '../../types' |
|
|
|
|
|
|
|
interface Database { |
|
|
|
client: CosmosClient |
|
|
@ -60,11 +61,20 @@ const plugin: Plugin<Server, IncomingMessage, ServerResponse, PluginOptions> = a |
|
|
|
}) |
|
|
|
|
|
|
|
server.setErrorHandler(function(error, request, reply) { |
|
|
|
request.log.error('Error: %s', error.message) |
|
|
|
|
|
|
|
reply.send({ |
|
|
|
const response: HttpError = { |
|
|
|
message: error.message, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
if (error.validation) { |
|
|
|
response.errors = error.validation.map(e => { |
|
|
|
return { |
|
|
|
field: trim(e.dataPath, '.'), |
|
|
|
message: e.message, |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
reply.send(response) |
|
|
|
}) |
|
|
|
|
|
|
|
server.register(authentication) |
|
|
|