<commit_before>package micro

import (
	"encoding/base64"
	"io/ioutil"
	"net/http"
	"net/url"
	"path"

	"github.com/cloudfoundry/bosh-agent/blobstore"
	bosherr "github.com/cloudfoundry/bosh-agent/errors"
	boshhandler "github.com/cloudfoundry/bosh-agent/handler"
	boshdispatcher "github.com/cloudfoundry/bosh-agent/httpsdispatcher"
	boshlog "github.com/cloudfoundry/bosh-agent/logger"
	boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
	boshsys "github.com/cloudfoundry/bosh-agent/system"
)

type HTTPSHandler struct {
	parsedURL   *url.URL
	logger      boshlog.Logger
	dispatcher  *boshdispatcher.HTTPSDispatcher
	fs          boshsys.FileSystem
	dirProvider boshdir.Provider
}

func NewHTTPSHandler(
	parsedURL *url.URL,
	logger boshlog.Logger,
	fs boshsys.FileSystem,
	dirProvider boshdir.Provider,
) (handler HTTPSHandler) {
	handler.parsedURL = parsedURL
	handler.logger = logger
	handler.fs = fs
	handler.dirProvider = dirProvider
	handler.dispatcher = boshdispatcher.NewHTTPSDispatcher(parsedURL, logger)
	return
}

func (h HTTPSHandler) Run(handlerFunc boshhandler.Func) error {
	err := h.Start(handlerFunc)
	if err != nil {
		return bosherr.WrapError(err, "Starting https handler")
	}
	return nil
}

func (h HTTPSHandler) Start(handlerFunc boshhandler.Func) error {
	h.dispatcher.AddRoute("/agent", h.agentHandler(handlerFunc))
	h.dispatcher.AddRoute("/blobs/", h.blobsHandler())
	h.dispatcher.Start()
	return nil
}

func (h HTTPSHandler) Stop() {
	h.dispatcher.Stop()
}

func (h HTTPSHandler) RegisterAdditionalFunc(handlerFunc boshhandler.Func) {
	panic("HTTPSHandler does not support registering additional handler funcs")
}
<commit_msg>Catch error from http dispatcher<commit_after>package micro

import (
	"encoding/base64"
	"io/ioutil"
	"net/http"
	"net/url"
	"path"

	"github.com/cloudfoundry/bosh-agent/blobstore"
	bosherr "github.com/cloudfoundry/bosh-agent/errors"
	boshhandler "github.com/cloudfoundry/bosh-agent/handler"
	boshdispatcher "github.com/cloudfoundry/bosh-agent/httpsdispatcher"
	boshlog "github.com/cloudfoundry/bosh-agent/logger"
	boshdir "github.com/cloudfoundry/bosh-agent/settings/directories"
	boshsys "github.com/cloudfoundry/bosh-agent/system"
)

type HTTPSHandler struct {
	parsedURL   *url.URL
	logger      boshlog.Logger
	dispatcher  *boshdispatcher.HTTPSDispatcher
	fs          boshsys.FileSystem
	dirProvider boshdir.Provider
}

func NewHTTPSHandler(
	parsedURL *url.URL,
	logger boshlog.Logger,
	fs boshsys.FileSystem,
	dirProvider boshdir.Provider,
) (handler HTTPSHandler) {
	handler.parsedURL = parsedURL
	handler.logger = logger
	handler.fs = fs
	handler.dirProvider = dirProvider
	handler.dispatcher = boshdispatcher.NewHTTPSDispatcher(parsedURL, logger)
	return
}

func (h HTTPSHandler) Run(handlerFunc boshhandler.Func) error {
	err := h.Start(handlerFunc)
	if err != nil {
		return bosherr.WrapError(err, "Starting https handler")
	}
	return nil
}

func (h HTTPSHandler) Start(handlerFunc boshhandler.Func) error {
	h.dispatcher.AddRoute("/agent", h.agentHandler(handlerFunc))
	h.dispatcher.AddRoute("/blobs/", h.blobsHandler())
	err := h.dispatcher.Start()
	return err
}

func (h HTTPSHandler) Stop() {
	h.dispatcher.Stop()
}

func (h HTTPSHandler) RegisterAdditionalFunc(handlerFunc boshhandler.Func) {
	panic("HTTPSHandler does not support registering additional handler funcs")
}

{'fraction_non_alphanumeric': 0.110381861575179, 'fraction_numerical': 0.0011933174224343676, 'mean_word_length': 5.1749539594843466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7622304', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1182, 'n_words': 219}