# all files / api/ open-file.js

100% Statements 17/17
100% Branches 4/4
100% Functions 5/5
100% Lines 3/3

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    1

    4

     'use strict';

    // Dependencies:
    import fileStructure from '../file-structure';

    // Errors:
    import errorHandler from '../errors/error-handler';
    import TractorError from '../errors/TractorError';

    export default { handler };

    function handler (request, response) {
        let { path } = request.query;

        return fileStructure.openFile(path)
        .then((file) => response.send(file))
        .catch(TractorError, error => errorHandler.handler(response, error))
        .catch(() => errorHandler.handler(response, new TractorError(`Could not open "${path}"`)));
    }