Monday, April 16, 2018

GCP .Net Core Error Reporting

If use Log, it will log duplicate, so just throw exception, code below is throw exception with response 500 and exception class.

//Startup.cs After this

app.UseGoogleTrace();

app.UseExceptionHandler(
 options =>
 {
     options.Run(
     async context =>
     {

         context.Response.Headers.Add("Access-Control-Allow-Origin", "*"); //Allow Origin
         context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
         context.Response.ContentType = "application/json";
         var ex = context.Features.Get<IExceptionHandlerFeature>();
         if (ex != null)
         {
             var err = JsonConvert.SerializeObject(ex.Error);
             await context.Response.WriteAsync(err).ConfigureAwait(false);
         }
     });
 }
);

//Before this 
app.UseMvc();

----------------

try
{
    return Ok(result);
}
catch (Exception ex)
{
    throw ex;
}

Tuesday, April 3, 2018

JS part 2


//Get From JSON , FIlter , and put in drop down

$.getJSON(
'https://fly.com/stations/file.json', function (list) {

    list = list.filter(function (item) {
        return item.StationType == "A";
    });

    for (var i in list) {
        if (list.hasOwnProperty(i)) {
            optionDes += "<option value='" + list[i].StationCode + "'>" + list[i].StationName + " (" + list[i].StationCode + ")</option>";
        }
    }

    optionDes += "</select>";
    document.getElementById("origin").innerHTML = optionDes;