<commit_before>package handler

import (
	"appengine"
	"encoding/json"
	"net/http"

	"github.com/gorilla/mux"

	"lib/locations"
	"lib/pois"
)

// PoisJSON returns pois
func PoisJSON(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	vars := mux.Vars(r)
	selectedLocation, exists := locations.GetById(r, vars["locationId"])
	if !exists {
		NotFoundJSON(w, r)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(pois.GetAsJSON(c, selectedLocation))
}

// NotFound handles 404 in JSON
func NotFoundJSON(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	errorResponse, jsonError := json.Marshal(map[string]string{
		"message": "Error 404 – Not found",
	})
	if jsonError != nil {
		c.Errorf("main.NotFoundJSON marshal: %v", jsonError)
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(404)
	w.Write(errorResponse)
}
<commit_msg>refacor(api): use go status code<commit_after>package handler

import (
	"appengine"
	"encoding/json"
	"net/http"

	"github.com/gorilla/mux"

	"lib/locations"
	"lib/pois"
)

// PoisJSON returns pois
func PoisJSON(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	vars := mux.Vars(r)
	selectedLocation, exists := locations.GetById(r, vars["locationId"])
	if !exists {
		NotFoundJSON(w, r)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(pois.GetAsJSON(c, selectedLocation))
}

// NotFound handles 404 in JSON
func NotFoundJSON(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	errorResponse, jsonError := json.Marshal(map[string]string{
		"message": "Error 404 – Not found",
	})
	if jsonError != nil {
		c.Errorf("main.NotFoundJSON marshal: %v", jsonError)
	}

	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusNotFound)
	w.Write(errorResponse)
}

{'fraction_non_alphanumeric': 0.15797958087049974, 'fraction_numerical': 0.008060182697474477, 'mean_word_length': 4.81875, 'pattern_counts': {'":': 2, '<': 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': '5871809', 'n_tokens_mistral': 713, 'n_tokens_neox': 678, 'n_words': 136}